Hi All,I was trying to automate my Password reset activity for Sql Logins from a central servr using Powershell.With the help of some useful tips from the below link, I was able to create a script : http://www.mssqltips.com/sqlservertip/1947/connect-to-sql-server-via-windows-powershell-with-sql-server-authentication/Initially I am just trying to read from the csv file and print the details to check if it works properly. Here is the script :[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null #imports the csv file with details $Items = Import-CSV D:\TEMP\test.csv -Delimiter "|" #Use the chosen delimiterForEach ($Item in $Items){ $Instance = $Item.ServerName $uname = $Item.uname $pwd = $Item.pwd $newpwd = $Item.newpwd$srv = new-object ('Microsoft.SqlServer.Management.Smo.Server') $Instance#This sets the sql authentication$srv.ConnectionContext.LoginSecure=$false; #This sets the login name $srv.ConnectionContext.set_Login($uname); #This sets the password $srv.ConnectionContext.set_Password($pwd) echo $Instanceecho $unameecho $pwdecho $newpwd}This script works fine and prints everything as desired. However, there is an error that pops up in the powershell window and I would like to handle this error before I proceed.The error is as below :[i]Exception calling "set_Login" with "1" argument(s): "Cannot apply value `null' to property Login: Value cannot be null."At line:11 char:33+ $srv.ConnectionContext.set_Login <<<< ($uname); + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException[/i]Can someone please let me know if there is anything wrong that I am doing here?Thanks a Lot !!!
↧