Skip to content

Instantly share code, notes, and snippets.

@Qwizi
Created February 2, 2026 11:40
Show Gist options
  • Select an option

  • Save Qwizi/fc4d06805d3ed0114071eefac38e97f4 to your computer and use it in GitHub Desktop.

Select an option

Save Qwizi/fc4d06805d3ed0114071eefac38e97f4 to your computer and use it in GitHub Desktop.
Optima alias
param(
[Parameter(Mandatory=$false)]
[string]$AliasName = "{nazwa_komputera}\optima",
[Parameter(Mandatory=$false)]
[string]$Server = "{ip_serwera}\optima"
)
Write-Host "Dodawanie aliasu SQL..."
Write-Host "Alias: $AliasName"
Write-Host "Adres SQL: $Server"
Write-Host ""
$value = "DBMSSOCN,$Server"
$paths = @(
"HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\MSSQLServer\Client\ConnectTo"
)
foreach ($path in $paths) {
if (-not (Test-Path $path)) {
New-Item -Path $path -Force | Out-Null
}
$existing = (Get-ItemProperty -Path $path -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $AliasName -ErrorAction SilentlyContinue)
if ($existing) {
Write-Host "Alias '$AliasName' juz istnieje w: $path"
} else {
Set-ItemProperty -Path $path -Name $AliasName -Value $value
Write-Host "Dodano alias '$AliasName' -> '$value' w: $path"
}
}
Write-Host ""
Write-Host "Gotowe! Alias bedzie widoczny w obu wersjach Cliconfg."
@Qwizi
Copy link
Copy Markdown
Author

Qwizi commented Feb 2, 2026

powershell -ExecutionPolicy Bypass -File alias.ps1 ^
    -AliasName "KOMPUTER01\optima" ^
    -Server "192.168.1.10\optima"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment