forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssert-ManagedServiceType.ps1
More file actions
68 lines (55 loc) · 2.6 KB
/
Assert-ManagedServiceType.ps1
File metadata and controls
68 lines (55 loc) · 2.6 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
<#
.SYNOPSIS
Assert that a computer managed service is of a certain type.
.DESCRIPTION
Assert that a computer managed service is of a certain type. If it is the
wrong type an exception is thrown.
.PARAMETER ServiceObject
Specifies the Service object to evaluate.
.PARAMETER ServiceType
Specifies the normalized service type to evaluate.
.EXAMPLE
$serviceObject = Get-SqlDscManagedComputerService -ServiceType 'DatabaseEngine'
Assert-ManagedServiceType -ServiceObject $serviceObject -ServiceType 'DatabaseEngine'
Asserts that the computer managed service object is of the type Database Engine.
.EXAMPLE
$serviceObject = Get-SqlDscManagedComputerService -ServiceType 'DatabaseEngine'
$serviceObject | Assert-ManagedServiceType -ServiceType 'DatabaseEngine'
Asserts that the computer managed service object is of the type Database Engine.
.INPUTS
`Microsoft.SqlServer.Management.Smo.Wmi.Service`
Accepts a SQL Server managed service object via the pipeline.
.OUTPUTS
None.
#>
function Assert-ManagedServiceType
{
[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.')]
[OutputType()]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Microsoft.SqlServer.Management.Smo.Wmi.Service]
$ServiceObject,
[Parameter(Mandatory = $true)]
[ValidateSet('DatabaseEngine', 'SqlServerAgent', 'Search', 'IntegrationServices', 'AnalysisServices', 'ReportingServices', 'SQLServerBrowser', 'NotificationServices')]
[System.String]
$ServiceType
)
process
{
$normalizedServiceType = ConvertFrom-ManagedServiceType -ServiceType $ServiceObject.Type
if ($normalizedServiceType -ne $ServiceType)
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.ManagedServiceType_Assert_WrongServiceType -f $ServiceType, $normalizedServiceType),
'AMST0001', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$ServiceObject
)
)
}
}
}