The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

refchamp (1) [Avatar] Offline
Hello I am a novice powershell user and I wanted to know if there is a way to change the admin password of remote machines using the poweshell scripts. Does anybody know where I can find one or a similar script that can be tweaked to perform this task?
kryten (2) [Avatar] Offline
Re: Change remote password with powershell
I needed to do the same thing and Brandon Shell over on the PS newsgroup supplied the guts of a script that works fine. I've modded it a bit, but here it is:-


function Invoke-ResetPassword{

# if $server is "" then assume that it's the local computer thats to be used
# so read the environmental table to get the computername
# this should not be the case when used by TST VOICE to change Application servers.
If(!($server)){$server = get-content env:COMPUTERNAME}

$dePath = "WinNT://$server/$user,user"
# if the -auth switch is ON (Which it will be!) collect the following extra information into the
# variables specified.

$lUser = Read-Host "Enter username of the account to be used to authenticate you on the remote server:-"
$lPassword = Read-Host "Enter the password for this account"
$myuser = new-Object System.DirectoryServices.DirectoryEntry($dePath,$lUser,$lPassword)
# If -auth is not specified......this should not happen though.
$myuser = new-Object System.DirectoryServices.DirectoryEntry($dePath)

# now do this:-

if($?){Write-Host "Password Reset Successful!"}
else{Write-Host "Reset Failed"}

# clear the screen

# collect the servername
$servname = Read-Host "Enter the computername of the server:-"
# collect the remote account username
$accountname = Read-Host "Enter the username of the remote account:-"
# collect the new password
$newpass = Read-Host "Enter the new password for this account:-"

# invoke the function from the top passing the arguments collected above with the authorisation switch ON
Invoke-ResetPassword -user $accountname -password $newpass -server $servname -auth


I'm really not sure that this bulletin board is the best place for technical questions as I've asked some already and with over 200+ views no-one replied! Maybe this is designed to talk about the book only?

Anyhow, hope the script helps!