forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssert-SqlDscLogin.ps1
More file actions
76 lines (60 loc) · 2.66 KB
/
Assert-SqlDscLogin.ps1
File metadata and controls
76 lines (60 loc) · 2.66 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
<#
.SYNOPSIS
Assert that the specified SQL Server principal exists as a login.
.DESCRIPTION
This command asserts that the specified SQL Server principal exists as a
login. If the principal does not exist as a login, a terminating error
is thrown.
.PARAMETER ServerObject
Specifies current server connection object.
.PARAMETER Name
Specifies the name of the principal that needs to exist as a login.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Assert-SqlDscLogin -Name 'MyLogin'
Asserts that the principal 'MyLogin' exists as a login.
.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
Assert-SqlDscLogin -ServerObject $serverObject -Name 'MyLogin'
Asserts that the principal 'MyLogin' exists as a login.
.INPUTS
`Microsoft.SqlServer.Management.Smo.Server`
Accepts a SQL Server server object via the pipeline.
.OUTPUTS
None.
.NOTES
This command throws a terminating error if the specified SQL Server
principal does not exist as a SQL server login.
#>
function Assert-SqlDscLogin
{
[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
{
Write-Verbose -Message ($script:localizedData.Assert_Login_CheckingLogin -f $Name, $ServerObject.InstanceName)
if (-not (Test-SqlDscIsLogin -ServerObject $ServerObject -Name $Name))
{
$missingLoginMessage = $script:localizedData.Assert_Login_LoginMissing -f $Name, $ServerObject.InstanceName
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$missingLoginMessage,
'ASDL0001', # cspell: disable-line
[System.Management.Automation.ErrorCategory]::ObjectNotFound,
$Name
)
)
}
Write-Debug -Message ($script:localizedData.Assert_Login_LoginExists -f $Name)
}
}