Ads

29 April 2014

Reset SA Password For Multiple Instance

Power Shell Script  :-

Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -EA Stop
Foreach ($list In $(Get-Content -Path p:\serverList.txt)) {
   $server = $list.split(":")
   $srvObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $server[0]
   $srvObject.Logins.Item('sa').ChangePassword($server[1])
   $srvObject.Logins.Item('sa').Alter()
}



The above uses the file "ServerList.txt", where we neeed to store the instance names and corresponding password in the following pattern,

[Instance Name]:{PASSWORD}
[Instance Name2]:{PASSWORD}
......




No comments:

Post a Comment