Created
July 18, 2013 22:58
-
-
Save cbilson/6033825 to your computer and use it in GitHub Desktop.
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
function New-SqlServerAlias($name, $server='.', $protocol='tcp', $port='1433') { | |
$options = New-Object System.Management.ConnectionOptions | |
$options.Context.Add('__ProviderArchitecture', 64) | |
$path = '\\.\root\microsoft\sqlserver\computermanagement11' | |
$scope = New-Object System.Management.ManagementScope($path, $options) | |
$scope.Connect() | |
$managementPath = New-Object System.Management.ManagementPath('SqlServerAlias') | |
$class = New-Object System.Management.ManagementClass($scope, $managementPath, $null) | |
$alias = $class.CreateInstance() | |
$alias.SetPropertyValue('AliasName', $name) | |
$alias.SetPropertyValue('ServerName', $server) | |
$alias.SetPropertyValue('ProtocolName', $protocol) | |
$alias.SetPropertyValue('ConnectionString', $port) | |
$alias.Put() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment