forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssert-SqlDscAgentOperator.ps1
More file actions
63 lines (48 loc) · 2.24 KB
/
Assert-SqlDscAgentOperator.ps1
File metadata and controls
63 lines (48 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Asserts that a SQL Server Agent Operator exists and throws a terminating error if not found.
.DESCRIPTION
This command asserts that a SQL Server Agent Operator exists using the provided
parameters. If the operator is not found, it throws a terminating error with a
generic localized error message.
.PARAMETER ServerObject
Specifies the server object on which to check for the operator.
.PARAMETER Name
Specifies the name of the operator to check for.
.INPUTS
`Microsoft.SqlServer.Management.Smo.Server`
Accepts a SQL Server server object via the pipeline.
.OUTPUTS
None.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Assert-SqlDscAgentOperator -Name 'TestOperator'
Asserts that the SQL Agent Operator 'TestOperator' exists, throws error if not found.
.EXAMPLE
Assert-SqlDscAgentOperator -ServerObject $serverObject -Name 'TestOperator'
Asserts that the SQL Agent Operator 'TestOperator' exists, throws error if not found.
#>
function Assert-SqlDscAgentOperator
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
[CmdletBinding()]
[OutputType()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Microsoft.SqlServer.Management.Smo.Server]
$ServerObject,
[Parameter(Mandatory = $true)]
[System.String]
$Name
)
process
{
$originalErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
# This will throw a terminating error if the operator is not found
$null = Get-AgentOperatorObject -ServerObject $ServerObject -Name $Name -ErrorAction 'Stop'
$ErrorActionPreference = $originalErrorActionPreference
# This command does not return anything if the operator exists
}
}