forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-SqlDscAgentAlert.ps1
More file actions
82 lines (66 loc) · 2.76 KB
/
Copy pathGet-SqlDscAgentAlert.ps1
File metadata and controls
82 lines (66 loc) · 2.76 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<#
.SYNOPSIS
Returns SQL Agent Alert information.
.DESCRIPTION
Returns SQL Agent Alert information from a SQL Server Database Engine instance.
.PARAMETER ServerObject
Specifies current server connection object.
.PARAMETER Name
Specifies the name of the SQL Agent Alert to retrieve. If not specified,
all alerts are returned.
.OUTPUTS
[Microsoft.SqlServer.Management.Smo.Agent.Alert[]]
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine
Get-SqlDscAgentAlert -ServerObject $serverObject
Returns all SQL Agent Alerts from the server.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine
Get-SqlDscAgentAlert -ServerObject $serverObject -Name 'MyAlert'
Returns the SQL Agent Alert named 'MyAlert'.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine
$serverObject | Get-SqlDscAgentAlert -Name 'MyAlert'
Returns the SQL Agent Alert named 'MyAlert' using pipeline input.
#>
function Get-SqlDscAgentAlert
{
[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([Microsoft.SqlServer.Management.Smo.Agent.Alert[]])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Microsoft.SqlServer.Management.Smo.Server]
$ServerObject,
[Parameter()]
[System.String]
$Name
)
# cSpell: ignore GSAA
process
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscAgentAlert_GettingAlerts)
$alertCollection = $ServerObject.JobServer.Alerts
if ($PSBoundParameters.ContainsKey('Name'))
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscAgentAlert_FilteringByName -f $Name)
$alertObject = $alertCollection | Where-Object -FilterScript { $_.Name -eq $Name }
if ($alertObject)
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscAgentAlert_AlertFound -f $Name)
return $alertObject
}
else
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscAgentAlert_AlertNotFound -f $Name)
return $null
}
}
else
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscAgentAlert_ReturningAllAlerts -f $alertCollection.Count)
return $alertCollection
}
}
}