forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvertFrom-ManagedServiceType.ps1
More file actions
121 lines (93 loc) · 3.2 KB
/
ConvertFrom-ManagedServiceType.ps1
File metadata and controls
121 lines (93 loc) · 3.2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<#
.SYNOPSIS
Converts a managed service type name to a normalized service type name.
.DESCRIPTION
Converts a managed service type name to its normalized service type name
equivalent.
.PARAMETER ServiceType
Specifies the managed service type to convert to the correct normalized
service type name.
.EXAMPLE
ConvertFrom-ManagedServiceType -ServiceType 'SqlServer'
Returns the normalized service type name 'DatabaseEngine' .
.INPUTS
`Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType`
Accepts a managed service type via the pipeline.
.OUTPUTS
`System.String`
Returns the normalized service type name.
#>
function ConvertFrom-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.')]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]
$ServiceType
)
process
{
# Map the normalized service type to a valid value from the managed service type.
switch ($ServiceType)
{
'SqlServer'
{
$serviceTypeValue = 'DatabaseEngine'
break
}
'SqlAgent'
{
$serviceTypeValue = 'SqlServerAgent'
break
}
'Search'
{
$serviceTypeValue = 'Search'
break
}
'SqlServerIntegrationService'
{
$serviceTypeValue = 'IntegrationServices'
break
}
'AnalysisServer'
{
$serviceTypeValue = 'AnalysisServices'
break
}
'ReportServer'
{
$serviceTypeValue = 'ReportingServices'
break
}
'SqlBrowser'
{
$serviceTypeValue = 'SQLServerBrowser'
break
}
'NotificationServer'
{
$serviceTypeValue = 'NotificationServices'
break
}
default
{
<#
This catches any future values in the enum ManagedServiceType
that are not yet supported.
#>
$writeErrorParameters = @{
Message = $script:localizedData.ManagedServiceType_ConvertFrom_UnknownServiceType -f $ServiceType
Category = 'InvalidOperation'
ErrorId = 'CFMST0001' # CSpell: disable-line
TargetObject = $ServiceType
}
Write-Error @writeErrorParameters
break
}
}
return $serviceTypeValue
}
}