Updating Remote Passwords with PowerShell

Changing passwords is always one of those fun tasks for any admin. It becomes even more challenging when your a Windows admin over hundreds of individual servers that are not part of the same domain.  Here’s my take on a PowerShell script to change the password of a local user on a remote system (or many remote systems), regardless of domain status.

I like to take the opportunity to use vSphere as a way to gather systems to run scripts against as opposed to the traditional serverlist.txt files.  This lets me target systems to run scripts against via any grouping provided by vSphere including folders, hosts, clusters, datacenters, etc.  My favorite is the use of folders as many folks already use these to group common systems together. Note you can always use the ‘VM’ folder which is the (hidden) root folder which holds all VMs if you want to take it that far.

So we’ll connect to vCenter via PowerCli and grab a list of Powered On Windows systems. Next comes connecting to each system via WMI and changing the password. Two sets of credentials are required, one used to connect to the remote system and the second being the account being updated (Note these can be the same account – you can logon as bob and change bob’s password).

In the script you will notice a -flush parameter.  This helps resolve the “Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.” issue.  Be aware that the -flush switch will remove all mapped drives and connections to all remote systems by simply running – net use * /d /y

Leave a Reply

Your email address will not be published. Required fields are marked *