forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-AgentAlertObject.ps1
More file actions
48 lines (36 loc) · 1.26 KB
/
Get-AgentAlertObject.ps1
File metadata and controls
48 lines (36 loc) · 1.26 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
<#
.SYNOPSIS
Gets a SQL Agent Alert object from the JobServer.
.DESCRIPTION
Gets a SQL Agent Alert object from the JobServer based on the specified name.
.PARAMETER ServerObject
Specifies the SQL Server object.
.PARAMETER Name
Specifies the name of the SQL Agent Alert.
.INPUTS
None.
.OUTPUTS
`Microsoft.SqlServer.Management.Smo.Agent.Alert`
Returns the SQL Agent Alert object when an alert with the specified name is found, or $null if not found.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine
Get-AgentAlertObject -ServerObject $serverObject -Name 'MyAlert'
Gets the SQL Agent Alert named 'MyAlert'.
#>
function Get-AgentAlertObject
{
[CmdletBinding()]
[OutputType([Microsoft.SqlServer.Management.Smo.Agent.Alert])]
param
(
[Parameter(Mandatory = $true)]
[Microsoft.SqlServer.Management.Smo.Server]
$ServerObject,
[Parameter(Mandatory = $true)]
[System.String]
$Name
)
Write-Verbose -Message ($script:localizedData.Get_AgentAlertObject_GettingAlert -f $Name)
$alertObject = $ServerObject.JobServer.Alerts | Where-Object -FilterScript { $_.Name -eq $Name }
return $alertObject
}