Change root password script

I discovered this end script that bradley4681 posted in the course http://communities.VMware.com/thread/172220?start=15 & tstart = 0 . For some reason any, that I am unable to respond to this thread, so I thought I would ask my question here. 

Although this script works fantastic, I want to invite me for the current password and the new password for root for the script, and then use that input to change the root password on every host listed in the hosts.txt file.

Is this possible?  I prefer not to change a script file and enter password data each month to change 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

Of course, you can replace these lines

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

with this

...
#Current Hosts Root Password
$rootpswd = Read-Host -Prompt "Old root password"
#New Root Password
$newpass = Read-Host -Prompt "New root password"
...

If you want to secure this you can add the parameter - AsSecureString on the Read-Host cmdlet.

But be careful when you want to use the passwords later in the script.

See question Powershell

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • Big change Root Password

    Hi Guy,

    I am trying to run the following script against vSphere 4.0 but it crashes saying:

    " Cannot validate the argument on the"Id"parameter. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. To: tank line: 37:26 + $acctMgr = Get-view-Id & lt; & lt; & lt; & lt;  "$si.content.accountmanager"

    The Script: * making of http://www.van-lieshout.com/2009/02/bulk-change-your-esx-root-password/

    #

    1. This script changes the password to root on all ESX host in the esxservers.txt text file

    #

    1. Add VI-box #.

    #Add - PSsnapin VMware.VimAutomation.Core

    #Initialize - VIToolkitEnvironment.ps1

    1. Get old titles of root

    $oldrootPassword = "Enter the old root password" Read-Host - AsSecureString

    $oldrootCredential = new-object - typename System.Management.Automation.PSCredential - argumentlist 'root', $oldrootPassword

    1. New information for the identification of root

    $newrootPassword = "Enter the new root password" Read-Host - AsSecureString

    $newrootCredential = new-object - typename System.Management.Automation.PSCredential - argumentlist 'root', $newrootPassword

    $newrootPassword2 = Read-Host "Retype new root password" - AsSecureString

    $newrootCredential2 = new-object - typename System.Management.Automation.PSCredential - argumentlist 'root', $newrootPassword2

    1. Compare passwords

    If ($newrootCredential.GetNetworkCredential ().) Password - ceq $newrootCredential2.GetNetworkCredential (). {Password)

    1. Create the new object of root account

    $rootaccount = new-Object VMware.Vim.HostPosixAccountSpec

    $rootaccount.id = 'root '.

    $rootaccount.password = $newrootCredential.GetNetworkCredential (). Password

    $rootaccount.shellAccess = ' / bin/bash ".

    1. The list of text file host servers to change the root password on

    Get-Content esxservers.txt | %{

    SE connect-VIServer $_-user root - password $oldrootCredential.GetNetworkCredential (). Password - ErrorAction SilentlyContinue - ErrorVariable ConnectError. Out-Null

    If ($ConnectError - not $Null) {}

    Write-Host "ERROR: unable to connect to the ESX Server: ' $_

    }

    Else {}

    $si = get-view ServiceInstance

    $acctMgr = get-view-Id $si.content.accountmanager

    $acctMgr.UpdateUser ($rootaccount)

    Write-Host "Root password changed successfully on ' $_

    Disconnect-VIServer-confirm: $False | Out-Null

    }

    }

    }

    Else {}

    Write-Host "ERROR: new root passwords do not match." Smooth... »

    }

    My Powershell skills are still very basic, but in progress, however .

    Everyone would be able to explain why it crashes and how can I solve it?

    Thanks in advance

    Very strange but this script works now and I wouldn't change a thing!

    I was close PowerGui Script Editor, and then open it again when I received your second answer. Indeed, very strange, but I guess I got a lot to learn about Powershell yet!

    Thanks for your quick responses so!

  • change root password

    If I change the root password on my host esx 4.1, do I need to do anything in Virtual Center because he then recognizes this change?

    No, vCenter Server creates its own user (vpxuser) on the ESXi hosts to access when the host is connected to vCenter. You may need to verify that the root account is not used for other applications.

    André

  • Consequences of change root password

    We lost our root password for our two esx3.5 boxes and I have some questions that I hope someone can help me with, as I am a fairly new admin of VMware.

    I have instructions on how to change the root password (http://www.petri.co.il/vmware-esx-server-root-password-reset-recovery-lost.htm) which look good, but I'm not sure on a number of things:

    (1) what else will be affected if the root password is changed? We have vcentre, vmotion, vcb and possibly other utilities that I I know not. If I change the root password, one of these (or other applications common/standard) will affect and need to be changed to reflect the new password? In my view, it is not recommended to use root for something like this, but I don't know if it happens.

    (2) we have two hosts in the cluster. Do I have reason to assume that I can change the root on one host at a time or make different from eachother? Not that I'm likely to make them different, but my plan is everything to a single host, reset the password on the void and see how it goes. If everything continues to work I then move everything to this host and reset the password on the second host, term, threaten things back where they should be. I am likely to face a problem that do it this way?

    Any advice or comments appreciated.

    Welcome to the forum.

    As written there is no consequence.

    This because the vCenter Server using the root connection only when guests first connects.

    Then he will add a new user (vpxa) and uses this user.

    André

  • Question - change the stupid root passwords


    I use the same passwords for root for too long to my vm hosts and need to change to improve safety.    The hosts are all added in Vcenter and clustered.    If I change the root password of the individial hosts, is what it's going to break the bond of vcenter?    I know that you type in passwords for root when connecting host to vcenter, but then it installs vpxuser, then I guess it should not occupy root changes after that.   I just wanted to confirm with someone who did this recently.

    (5.0 and 5.1 with Vcenter 5.1 ESXi)

    Hello

    No, the root passwords change does not affect the vCenter.  No link will be broken. It authenticates just the first time that you add the vCenter Server inventory.

    You even change passwords on multiple hosts in a row only to avoid the hassle of Power-Cli scripts.

    Thank you

    Avinash

  • Need a script to change the password of admin for all the VMs (windows)

    Need a script to change the password of admin for all the VMs (windows)

    Hi LucD,

    Need your help about changing the password to root for Linux VM.

    It throws the following error when I run on Linux VM

    Invoke VMScript: 10/04/2013-16:52:02 Invoke VMScript Could not authenticate with the guest operating system by using the supplied credentials.

    Thank you

    Suresh

  • Change the root password interactively

    Hello
    I want to change the password of root interactively using a configuration script, where I change many more parameters, without specifying the new root password in the configuration script.
    I would like the script to give me a chance to type the password to myself.
    Something like when you started a new cmd session in a .bat script using the cmd /c
    Thank you

    Take a look at this script and see if the way they work for you: http://communities.vmware.com/thread/412623

  • Change the root password

    Hello!

    I would like to change the password to root for our ESX 4.0 servers. Problems or advice?

    Unless you actually use the root connection in some application or script, and the saved password here - no problems.

    ---

    MCP, MCTS, VCP, VMware vExpert 2009

    http://blog.vadmin.ru

  • Try to set / change the password BIOS admin via the script WMI on ThinkStation D20

    Hello Lenovo Community!

    Start using the WMI Lenovo_SetBiosSetting class on a D20 system.

    If I understand the documentation that there is a limitation on the BIOS password in the past, but I updated to the latest BIOS Rev who support States was added for this feature.

    I use a script that changes the supervisor on computers password successfully thinkpad, but when even to run the script from command line on the D20 system it returns "SUCCESS" however to change the password did not effect!

    I'm using the right parameters are the standard of lenovo

    ' pap, oldpass newpass, ascii, we.

    I thought maybe "pap" is not the correct setting for password Admin on the D20, however the WMI available, posted 2010 guide, does not show otherwise.

    Someone at - it an example script that they can display successfully change the password on a D20 system?

    Please and thx!

    Did you run the SaveSetting script after changing the password?

    You can get the SaveSetting script from the sample scripts D20 located at the following link:

    http://support.Lenovo.com/en_US/downloads/detail.page?docid=UM002033

    You can use the script SetAdminPassword from the library of scripts of series E, then a follow-up that with something like what follows before restarting:

    "cscript SaveSetting.vbs" originalpwd, ascii, we.

    Replace 'originalpwd' with all what your existing password was at the time wherever you booted the system.

  • Can I change the root password in VoP Server Explorer?

    Hello

    I was encouraged to see VoP Server Explorer, but my network does not have any system to have a default root password. Can I change the root user password?

    Thank you!

    Jennifer Flanagan

    Altogether.  Just connect to the console as root and type 'passwd' to change the root password.  Be sure to keep track of what you set, because there is little recourse except in single-user mode if it goes astray.

  • What should I do on vCenter vSphere Web Client after you change the host root password?

    Hello

    When we implemented vCenter our Organization, we used a regular password to the account 'root' on each ESXi host.

    So, I installed vCenter and added the hosts on it to manage.

    When I added them, they've asked for the root password power connect.

    Ok. Everything was fine.

    Now, we want to change the password to root for each ESXi host.

    My question is: what should I do to make sure that vCenter will always be able to connect to the ESXi hosts, because the account used to connect the first time change his password?

    My question is: what should I do to make sure that vCenter will always be able to connect to the ESXi hosts, because the account used to connect the first time change his password?

    Nothing, after the host is added to vCenter, a user named vpxuser is created automatically on the ESXi host and vCenter uses this user to connect and manage the host.

  • Help, I changed the password of root ESXi via powerCli, now I can not connect with the web client or the console.

    Help, I've changed the root ESXi via powerCli password, now I can not connect with the web client or the console, but I can still connect to powerCli. The command I used was;

    SE connect-VIServer esxihostname-user root - password newpasswd

    This production network btw, I have connected to each host and run the above command, these ESXi hosts are not on a domain

    y at - it something I have left out. I really appreciate any assistance that you people can provide.

    Thank you, Joe

    It is probably a longshot, but a lot of things in the land of windows is not sensitive to capital letters as Unix is.  I wonder if your new password you put through powerCLI mixed uppercase in it and if the capitalization was abandoned by command windows powerCLI Analyzer, or he interpreted as all capitals or something.   If you can still get through the powerCLI you could try to reset the password again to something simple without capitalization mixed case and if your password on ESXi strategy requires a special character, try something different than a "$", like a "_" (I find that a '_' is less likely than some other special characters (, as a '-' or a ' / ' to cause problems with analyzers.).

    Edit:

    Another thing, you can try before playing with the password once again, is to create a different username ESXi using powerCLI and see if the password ends up what you think, it should be, and if you can get with the client vsphere using it.  In this way, you can find out if there are some problems with certain characters or Cap through command powerCLI Analyzer without losing your remaining root by powerCLI access.  After some tests, you can understand what went wrong with your initial password change and may be able to fix it with less risk of losing access.  I also assume that you can not create a new username on ESXi who is able to change the root password no matter what authority give you it, otherwise, you could create a new username with PowerCLI, then connect to the client vsphere with it and change the password to root from there.

  • Change of the Esx server root password.

    Hello friends,

    I have a small queries if you change the root on Esx server password there will be an impact on virtual infrastructure if it so please explain what effect might be on OS comments and please let me know how to change the password if it is not an impact. the Esx version is 3.5...

    Thank you

    Unless you use any application that connects to the host by using the credentials of the root, there should be no problem with changing the root password. Virtual Center uses its own (vpxuser) user to access the host.

    André

  • change the password for root esxi and esx?

    Hello

    Is there an easy way to change passwords for root of esx esxi via powercli hosts?

    Thank you!!!

    You can use the Set-VMHostAccount cmdlet to change the password of an ESX/ESXi server. Remember that you must connect directly to the host to do.

    SE connect-VIServer-Server ESX1.yourdomain .com - user root - password secret

    Game-VMHostAccount - UserAccount root - password topsecret

    Best regards, Robert

  • Cannot change the default root password

    Try to change the password of the administrator of the root of the ESXi 4.1.

    For any password just keep getting the following message is displayed:

    Call "HostLocalAccountManager.UpdateUser" to object "ha-localacctmgr" on ESXi «...» "failed.

    In order to change the root password, you need to connect to the ESXi server from the console.

    Connect to the ESX console using the root password.

    #passwd new password

    This will change your root password.

Maybe you are looking for

  • How to get OCR working

    Hello Anyone can guide me please you the steps to make the work of OCR in document scan. I scan the document, but can see an option that can enable or show me OCR in action. Thank you Shivani

  • Satellite A - CD/DVD drive problems

    Hi guys go crazy... I have the following questions, trying to burn a cd or dvd. Sometimes I'm not recignise the disc as a blank disc ready for use, sometimes it burns then shows nothing on the disc, sometimes it burns more than one disk then fails, s

  • Inspiron 15 do not detect the headphones into the audio input jack

    Yes, I checked to make sure it wasn't the atria. I used 2 different pairs, each of the works fine on my other computer. My laptop has been recently upgraded to Windows 8.1. Since then, the audio Jack was my ear has been detected. This has not happene

  • General disaster

    After migrating to Windows 10 I suddenly found that I can access is no longer my own data. I have MS Office 365, but I can longer open Outlook, it tells me that I do not have access. Something obviously change in the settings of MS. I have restored t

  • Link to Windows 8 on a computer during installation

    Building out of this post http://Windows.Microsoft.com/en-us/Windows/answers?TID=eac28620-204e-498d-AE6A-ce5c28300591 I am currently using a Mac and I downloaded the Setup file of Windows 8. OSGS14-WindowsSetupBox-32bitand64bit-English - 4141408.exe