-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from PowerShell/dev
Merging release pull request
- Loading branch information
Showing
45 changed files
with
11,502 additions
and
545 deletions.
There are no files selected for viewing
285 changes: 144 additions & 141 deletions
285
DSCResources/MSFT_xSQLAOGroupEnsure/MSFT_xSQLAOGroupEnsure.psm1
Large diffs are not rendered by default.
Oops, something went wrong.
28 changes: 13 additions & 15 deletions
28
DSCResources/MSFT_xSQLAOGroupEnsure/MSFT_xSQLAOGroupEnsure.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
|
||
[ClassVersion("1.0.0.0"), FriendlyName("xSQLAOGroupEnsure")] | ||
class MSFT_xSQLAOGroupEnsure : OMI_BaseResource | ||
{ | ||
[Key, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
[Key] String AvailabilityGroupName; | ||
[Write] String AvailabilityGroupNameListener; | ||
[Write] String AvailabilityGroupNameIP[]; | ||
[Write] String AvailabilityGroupSubMask[]; | ||
[Write] Uint32 AvailabilityGroupPort; | ||
[Write, ValueMap{"None","ReadOnly","ReadIntent"}, Values{"None","ReadOnly","ReadIntent"}] String ReadableSecondary; | ||
[Write, ValueMap{"Primary","Secondary"}, Values{"Primary","Secondary"}] String AutoBackupPreference; | ||
[Write] Uint32 BackupPriority; | ||
[Write] Uint32 EndPointPort; | ||
[Write] String SQLServer; | ||
[Write] String SQLInstanceName; | ||
[Required, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to Grant Permissions in SQL.")] String SetupCredential; | ||
[Key, Description("Determines whether the availability group should be added or removed."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
[Key, Description("Name for availability group.")] String AvailabilityGroupName; | ||
[Write, Description("Listener name for availability group.")] String AvailabilityGroupNameListener; | ||
[Write, Description("List of IP addresses associated with listener.")] String AvailabilityGroupNameIP[]; | ||
[Write, Description("Network subnetmask for listener.")] String AvailabilityGroupSubMask[]; | ||
[Write, Description("Port availability group should listen on.")] Uint32 AvailabilityGroupPort; | ||
[Write, Description("Mode secondaries should operate under (None, ReadOnly, ReadIntent)."), ValueMap{"None","ReadOnly","ReadIntent"}, Values{"None","ReadOnly","ReadIntent"}] String ReadableSecondary; | ||
[Write, Description("Where backups should be backed up from (Primary, Secondary)."), ValueMap{"Primary","Secondary"}, Values{"Primary","Secondary"}] String AutoBackupPreference; | ||
[Write, Description("The percentage weight for backup prority (default 50).")] Uint32 BackupPriority; | ||
[Write, Description("he TCP port for the SQL AG Endpoint (default 5022).")] Uint32 EndPointPort; | ||
[Write, Description("The SQL Server for the database.")] String SQLServer; | ||
[Write, Description("The SQL instance for the database.")] String SQLInstanceName; | ||
[Required, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to Grant Permissions on SQL Server, set this to $null to use Windows Authentication.")] String SetupCredential; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
# | ||
# xSQLAlias: DSC resource to configure Client Aliases part of xSQLServer | ||
# | ||
|
||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ServerName | ||
) | ||
|
||
$returnValue = @{ | ||
Name = [System.String] $Name | ||
Protocol = [System.String] '' | ||
ServerName = [System.String] '' | ||
TcpPort = [System.UInt16] 0 | ||
PipeName = [System.String] '' | ||
Ensure = [System.String] 'Absent' | ||
} | ||
|
||
$protocolTcp = 'DBMSSOCN' | ||
$protocolNamedPipes = 'DBNMPNTW' | ||
|
||
Write-Verbose "Get the client alias $Name" | ||
|
||
<# | ||
Get-ItemProperty will either return $null if no value is set, or if value is set, it will always | ||
return a value in the format 'DBNMPNTW,\\ServerName\PIPE\sql\query' or 'DBMSSOCN,ServerName.company.local,1433' | ||
#> | ||
$itemValue = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue | ||
if ((Get-WmiOSArchitecture) -eq '64-bit') | ||
{ | ||
Write-Verbose "64-bit Operating System. Also get the client alias $Name from Wow6432Node" | ||
|
||
$isWow6432Node = $true | ||
$itemValueWow6432Node = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue | ||
} | ||
|
||
if ((-not $isWow6432Node -and $null -ne $itemValue ) -or | ||
( ($null -ne $itemValue -and $null -ne $itemValueWow6432Node) -and | ||
($isWow6432Node -and $itemValueWow6432Node."$Name" -eq $itemValue."$Name") )) | ||
{ | ||
$itemConfig = $itemValue."$Name" | ConvertFrom-Csv -Header 'Protocol','ServerName','TcpPort' | ||
if ($itemConfig) | ||
{ | ||
if ($itemConfig.Protocol -eq $protocolTcp) | ||
{ | ||
$returnValue.Ensure = 'Present' | ||
$returnValue.Protocol = 'TCP' | ||
$returnValue.ServerName = $itemConfig.ServerName | ||
$returnValue.TcpPort = $itemConfig.TcpPort | ||
} | ||
elseif ($itemConfig.Protocol -eq $protocolNamedPipes) | ||
{ | ||
$returnValue.Ensure = 'Present' | ||
$returnValue.Protocol = 'NP' | ||
$returnValue.PipeName = $itemConfig.ServerName | ||
} | ||
} | ||
} | ||
|
||
$returnValue | ||
} | ||
|
||
function Set-TargetResource | ||
{ | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name, | ||
|
||
[ValidateSet("TCP","NP")] | ||
[System.String] | ||
$Protocol = 'TCP', | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ServerName, | ||
|
||
[System.UInt16] | ||
$TcpPort = 1433, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
if ($Protocol -eq 'NP') | ||
{ | ||
$itemValue = "DBNMPNTW,\\$ServerName\PIPE\sql\query" | ||
} | ||
|
||
if ($Protocol -eq 'TCP') | ||
{ | ||
$itemValue = "DBMSSOCN,$ServerName,$TcpPort" | ||
} | ||
|
||
$registryPath = 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' | ||
$registryPathWow6432Node = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' | ||
|
||
if ($Ensure -eq 'Present') | ||
{ | ||
if ($PSCmdlet.ShouldProcess($Name, 'Setting the client alias')) | ||
{ | ||
if (!(Test-Path -Path $registryPath)) | ||
{ | ||
New-Item -Path $registryPath | Out-Null | ||
} | ||
|
||
Set-ItemProperty -Path $registryPath -Name $Name -Value $itemValue | Out-Null | ||
} | ||
|
||
# If this is a 64-bit OS then also update Wow6432Node | ||
if ((Get-WmiOSArchitecture) -eq '64-bit') | ||
{ | ||
if ($PSCmdlet.ShouldProcess($Name, 'Setting the client alias (32-bit)')) | ||
{ | ||
if (!(Test-Path -Path $registryPathWow6432Node)) | ||
{ | ||
New-Item -Path $registryPathWow6432Node | Out-Null | ||
} | ||
|
||
Set-ItemProperty -Path $registryPathWow6432Node -Name $Name -Value $itemValue | Out-Null | ||
} | ||
} | ||
} | ||
|
||
if ($Ensure -eq 'Absent') | ||
{ | ||
if ($PSCmdlet.ShouldProcess($Name, 'Remove the client alias')) | ||
{ | ||
if (Test-Path -Path $registryPath) | ||
{ | ||
Remove-ItemProperty -Path $registryPath -Name $Name | ||
} | ||
} | ||
|
||
# If this is a 64-bit OS then also remove from Wow6432Node | ||
if ((Get-WmiOSArchitecture) -eq '64-bit' -and (Test-Path -Path $registryPathWow6432Node)) | ||
{ | ||
if ($PSCmdlet.ShouldProcess($Name, 'Remove the client alias (32-bit)')) | ||
{ | ||
Remove-ItemProperty -Path $registryPathWow6432Node -Name $Name | ||
} | ||
} | ||
} | ||
} | ||
|
||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Name, | ||
|
||
[ValidateSet("TCP","NP")] | ||
[System.String] | ||
$Protocol = 'TCP', | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ServerName, | ||
|
||
[System.UInt16] | ||
$TcpPort = 1433, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
$result = $false | ||
|
||
$currentValues = Get-TargetResource -Name $Name -ServerName $ServerName | ||
if ($Ensure -eq $currentValues.Ensure) | ||
{ | ||
if( $Ensure -eq 'Absent' ) | ||
{ | ||
$result = $true | ||
} | ||
else { | ||
Write-Verbose "Ensure is in the desired state. Verifying values." | ||
|
||
if ($Protocol -eq $currentValues.Protocol) | ||
{ | ||
switch ($Protocol) | ||
{ | ||
'NP' | ||
{ | ||
if ($currentValues.PipeName -eq "\\$ServerName\PIPE\sql\query") | ||
{ | ||
$result = $true | ||
} | ||
} | ||
|
||
'TCP' | ||
{ | ||
if ($currentValues.ServerName -eq $ServerName -and | ||
$currentValues.TcpPort -eq $TcpPort) | ||
{ | ||
$result = $true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($result) | ||
{ | ||
Write-Verbose -Message 'In the desired state' | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message 'Not in the desired state' | ||
} | ||
|
||
return $result | ||
} | ||
|
||
function Get-WmiOSArchitecture | ||
{ | ||
return (Get-WmiObject -Class win32_OperatingSystem).OSArchitecture | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("xSQLAlias")] | ||
class MSFT_xSQLAlias : OMI_BaseResource | ||
{ | ||
[Key, Description("The name of Alias (e.g. svr01\\inst01).")] String Name; | ||
[Write, Description("Protocol to use when connecting. Valid values are 'TCP' or 'NP' (Named Pipes). Default value is 'TCP'."), ValueMap{"TCP","NP"}, Values{"TCP","NP"}] String Protocol; | ||
[Key, Description("The SQL Server you are aliasing (the netbios name or FQDN).")] String ServerName; | ||
[Write, Description("The TCP port SQL is listening on. Only used when protocol is set to 'TCP'. Default value is port 1433.")] UInt16 TcpPort; | ||
[Read, Description("Named Pipes path from the Get-TargetResource method.")] String PipeName; | ||
[Write, Description("Determines whether the alias should be added or removed. Default value is 'Present'"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
}; |
Oops, something went wrong.