Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Root Password Change Script

$
0
0

I discovered this fine script that bradley4681 posted over at http://communities.vmware.com/thread/172220?start=15&tstart=0. For some reason I am unable to reply to that thread, so I thought I would ask my question here. 

 

Even though this script works fantastic, I would like for the script to prompt me for the current root password and for the new root password, and then use that input to change the root password on each host listed in the hosts.txt file. 

 

Is this possible?  I would rather not edit a script file and enter the password data every month to change the passwords. 

 

#Starts a transcript of the script output
Start-Transcript -path "x:\log.txt"

#Gets a list of hosts to change passwords for, make sure there is no break after the last host
$vihosts = Get-Content "x:\hosts.txt"

#Starts Error Report recording
$errReport =@()

#Current Hosts Root Password
$rootpswd = 'currentpassword'
#New Root Password
$newpass = 'newpassword'

#Starts the process and loops until the last host in the host.txt file is reached
foreach ($singleViserver in $vihosts){

     #Connects to each host from the hosts.txt list and also continues on any error to finish the list     Connect-VIServer $singleViserver -User root -Password $rootpswd -ErrorAction SilentlyContinue -ErrorVariable err               $errReport += $err     if($err.Count -eq 0){     #Sets the root password     Set-VMHostAccount -UserAccount root -Password $newpass     }          #Disconnects from each server and suppresses the confirmation     Disconnect-VIServer -Confirm:$False     $errReport += $err     $err = ""
}

#Outputs the error report to a CSV file, if file is empty then no errors.
$errReport | Export-Csv ".\Pass-HostReport.csv" -NoTypeInformation

#Stops the transcript
Stop-Transcript

 


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>