Skip to content

Commit

Permalink
Changes to xSQLAlias
Browse files Browse the repository at this point in the history
I introduced a bug when doing code changes. Now it creates the key correctly before creating the alias on a new system.
  • Loading branch information
johlju committed Aug 22, 2016
1 parent b655a04 commit 09fe0b6
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions DSCResources/MSFT_xSQLAlias/MSFT_xSQLAlias.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,29 @@ function Set-TargetResource
# Logic based on ensure value Present
if ($Ensure -eq 'Present')
{
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo')
Write-Debug -Message 'Check if value requires changing'

$currentValue = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue
if ($null -ne $currentValue -and $itemValue -ne $currentValue)
{
Write-Debug -Message 'Check if value requires changing'
$currentValue = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue
if ($null -ne $currentValue -and $itemValue -ne $currentValue)
if ($PSCmdlet.ShouldProcess($Name,"Changing the client alias (64-bit)"))
{
if ($PSCmdlet.ShouldProcess($Name,"Changing the client alias (64-bit)"))
{
Write-Debug -Message 'Set-ItemProperty'
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
}
Write-Debug -Message 'Set-ItemProperty'
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
}
elseif ($null -eq $currentValue)
}
elseif ($null -eq $currentValue)
{
if ($PSCmdlet.ShouldProcess($Name,"Create client alias (64-bit)"))
{
if ($PSCmdlet.ShouldProcess($Name,"Create client alias (64-bit)"))
if (!(Test-Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo'))
{
Write-Debug -Message 'New-ItemProperty'
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue | Out-Null
Write-Debug -Message 'New-Item'
New-Item -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' | Out-Null
}

Write-Debug -Message 'New-ItemProperty'
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue | Out-Null
}
}

Expand All @@ -124,25 +128,28 @@ function Set-TargetResource
if ((Get-Wmiobject -Class win32_OperatingSystem).OSArchitecture -eq '64-bit')
{
Write-Debug -Message 'Is 64Bit'
if (Test-Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo')
Write-Debug -Message 'Check if value requires changing'
$currentValue = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue
if ($null -ne $currentValue -and $itemValue -ne $currentValue)
{
Write-Debug -Message 'Check if value requires changing'
$currentValue = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -ErrorAction SilentlyContinue
if ($null -ne $currentValue -and $itemValue -ne $currentValue)
if ($PSCmdlet.ShouldProcess($Name,"Changing the client alias (32-bit)"))
{
if ($PSCmdlet.ShouldProcess($Name,"Changing the client alias (32-bit)"))
{
Write-Debug -Message 'Set-ItemProperty'
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
}
Write-Debug -Message 'Set-ItemProperty'
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
}
elseif ($null -eq $currentValue)
}
elseif ($null -eq $currentValue)
{
if ($PSCmdlet.ShouldProcess($Name,"Create client alias (32-bit)"))
{
if ($PSCmdlet.ShouldProcess($Name,"Create client alias (32-bit)"))
if (!(Test-Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo'))
{
Write-Debug -Message 'New-ItemProperty'
New-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
Write-Debug -Message 'New-Item'
New-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' | Out-Null
}

Write-Debug -Message 'New-ItemProperty'
New-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' -Name $Name -Value $itemValue
}
}
}
Expand Down

0 comments on commit 09fe0b6

Please sign in to comment.