We've used the below script succesffuly up and through vSphere 4.1. With ESXi 5, the code errors. Any help would be greatly appreciated.
http://www.van-lieshout.com/2009/02/bulk-change-your-esx-root-password/
error:
Exception calling "UpdateUser" with "1" argument(s): "A specified parameter was
not correct.
"
At C:\scripts\changeESXPassword.ps1:34 char:23
+ $acctMgr.UpdateUser <<<< ($rootaccount)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
PowerCLI version:
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.0.1 build 581491
---------------
Snapin Versions
---------------
VMware AutoDeploy PowerCLI Component 5.0 build 544967
VMware ImageBuilder PowerCLI Component 5.0 build 544967
VMware License PowerCLI Component 5.0 build 544881
VMware vSphere PowerCLI Component 5.0 build 581435
Did you try with single quotes ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try the one in Change the root password in hosts and Host Profiles ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have not... However, I need to change 130 ESXi root passwords. Would I just connect to vCenter first then run the script? Or do I have to connect to each of the 130 Hosts individually?
You only need to connect to the vCenter, the script will take all ESXi hosts, known on the vCenter, one by one, except for the ones you specify in the $excludeServers variable, and change the root password.
The script assumes that all your ESXi servers, except the ones in $excludeServers, use the same root password.
Old password in $currentPswd and new password in $newPswd.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
here is what I'm doing, which is probably wrong. ![]()
Open PowerCLI and connect-viserver <vCenter>
then .\changerootpassword.ps1
...and I get the below error
Set-VMHostAccount : 5/14/2012 11:13:58 AM Set-VMHostAccount A specifi
ed parameter was not correct.
At C:\scripts\changerootpassword.ps1:13 char:20
+ Set-VMHostAccount <<<< -UserAccount root -Password $newPswd -Confirm:$fals
e | Out-Null
+ CategoryInfo : NotSpecified: (:) [Set-VMHostAccount], InvalidAr
gument
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_NewVmHostGr
oupAccount_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVM
HostAccount
Our password does have spacees in it, but is setup as
$currentPswd = "This is the old password..."
$newPswd = "This is the new password..."
Did you try with single quotes ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
neither works... don't know what's wrong.
Set-VMHostAccount : 5/14/2012 11:35:17 AM Set-VMHostAccount A specifi
ed parameter was not correct.
At C:\scripts\changerootpassword.ps1:13 char:20
+ Set-VMHostAccount <<<< -UserAccount root -Password $newPswd -Confirm:$fals
e | Out-Null
+ CategoryInfo : NotSpecified: (:) [Set-VMHostAccount], InvalidAr
gument
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_NewVmHostGr
oupAccount_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVM
HostAccount
code:
$currentPswd = 'this is our old password...'
$newPswd = 'this is our new password...'
$excludeServers =
$multiState = (Get-PowerCLIConfiguration).DefaultVIServerMode
$warnings = (Get-PowerCLIConfiguration).DisplayDeprecationWarnings
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false -DisplayDeprecationWarnings:$false | Out-Null
Get-VMHost | where{$excludeServers -notcontains $_.Name.Split('.')[0]} | %{
Connect-VIServer -Server $_.Name -User root -Password $currentPswd | Out-Null
Write-Verbose "Connected to $_"
Set-VMHostAccount -UserAccount root -Password $newPswd -Confirm:$false | Out-Null
Disconnect-VIServer -Server $_.Name -Confirm:$false
}
Set-PowerCLIConfiguration -DefaultVIServerMode $multiState -DisplayDeprecationWarnings $warnings -Confirm:$false | Out-Null
I figured it out.....
Our new password was too long. Once I shortened the new password, all is good.
Thank you sir!
Try escaping the blanks with the back-tick character.
$currentPswd = "this` is` our` old` password..."
$newPswd = "this` is` our` new` password..."
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
More than 40 chars, you guys using a book as a password ![]()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
gotta keep those non VI folks out of our stuff. ![]()
Thank again for your help!
I am guessing the password is
Stayouttahereallofyounonviguysyoudonotbelomgonoursyatemsallyourbasearebelongtous
![]()
- Josh Atwell
Sent from mobile device. Please excuse autocorrect errors.
ours was a bit longer![]()
