VMware Cloud Community
Troy_Clavell
Immortal
Immortal
Jump to solution

Change ESXi Root Password

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you try with single quotes ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

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

Troy_Clavell
Immortal
Immortal
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Troy_Clavell
Immortal
Immortal
Jump to solution

here is what I'm doing, which is probably wrong. Smiley Happy

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..."
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try with single quotes ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

I figured it out.....

Our new password was too long.  Once I shortened the new password, all is good.

Thank you sir!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

More than 40 chars, you guys using a book as a password Smiley Wink


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

gotta keep those non VI folks out of our stuff.  Smiley Wink

Thank again for your help!

Reply
0 Kudos
aerodevil
Hot Shot
Hot Shot
Jump to solution

I am guessing the password is

Stayouttahereallofyounonviguysyoudonotbelomgonoursyatemsallyourbasearebelongtous

Smiley Happy

- Josh Atwell

Sent from mobile device. Please excuse autocorrect errors.

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

ours was a bit longerSmiley Wink

Reply
0 Kudos