-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOS_Add_Update_SQL_ALIAS.ps1
More file actions
46 lines (40 loc) · 1.69 KB
/
OS_Add_Update_SQL_ALIAS.ps1
File metadata and controls
46 lines (40 loc) · 1.69 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
####################################################################################
# Written By:Dave Hodge, MCS
# Purpose: Create new SQL Alias or update existing SQL Alias entries based on logged
# in domain
####################################################################################
Function UpdateAlias
{
Param([string]$Key,[string]$Value,[string]$Description)
write-host "******************************************************"
write-host "SQL Alias Function"
write-host "Key: $Key"
write-host "Value: $Value"
write-host "Description: $Description"
$Path = "HKLM:\Software\Microsoft\MSSQLServer\Client\ConnectTo"
if(-NOT (Test-Path $Path))
{
New-Item $Path
}
if(-NOT (Get-ItemProperty -Path $Path -Name "$Key"))
{
WRITE-HOST "------------------------------------------------------------"
WRITE-HOST "Creating entry..."
New-ItemProperty -Path $Path -Name $Key -PropertyType String -Value "DBMSSOCN,$Value,15001"
}
ELSE
{
WRITE-HOST "------------------------------------------------------------"
$oldValue = Get-ItemProperty -Path "$Path" -Name $Key
if($($oldvalue.$Key).Tostring().toUpper() -ne ("DBMSSOCN,$Value,15001").Tostring().toUpper())
{
WRITE-HOST "Updating entry..."
write-host "Changing $Key from '$($oldvalue.$Key)' to 'DBMSSOCN,$Value,1433'" -ForegroundColor Green
Set-ItemProperty -Path "$Path" -Name "$Key" -Value "DBMSSOCN,$Value,1433"
}
else
{
WRITE-HOST "Entries match, no changes made..." -ForegroundColor Red
}
}
}