I am trying to get a script which will reconnect all of the ESX hosts when using a different vCenter server (same database though). I found the basics of what I need here:
But the only problem with that one is that the script has the password in clear text. I would prefer to prompt for the password, as with the Read-Host -AsSecureString option. My script below works fine without the -AsSecureString option....when the Read-Host is not masked. Can anyone tell me how to get it working with the -AsSecureString?
$password = Read-Host -assecurestring "Please enter the root password"
Get-VMHost | % { $view = Get-View $_.id }
$arg = New-Object vmware.vim.hostconnectspec
$arg.userName = "root"
$arg.password = $password
$arg.force = $true
$view.ReconnectHost($arg)
Thanks!
Kyle
The password property in the HostConnectSpec object requires a clear-text password.
That means you would have to use the method Robert provided in that post.
I attached a file (since the forum SW doesn't like square brackets) with your script adapted for that method.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There just has been another post that addressed the same problem.
Have a look at
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD.
I had seen that, but it hasn't worked for me. I get the same error I did before. I think my situation is slightly different because I am passing the password into an argument for the reconnect host? I am not sure - I am still pretty new to PowerCLI.
Here's what I've got with your $cred variable.
Clear-Host $vc= Read-Host "Please enter the FQDN of the vCenter server that is being activated" Connect-VIServer $vc Clear-Host $passwd = Read-Host -AsSecureString "Please enter the root password" Get-VMHost | % { $view = Get-View $_.id } $arg = New-Object vmware.vim.hostconnectspec $arg.username = "root" $arg.force = $true $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $arg.userName,$passwd $arg.password = $cred $view.ReconnectHost($arg)
And here is the error, which is the same error I get without the $cred variable (screenshot).
Thanks for your help!
Kyle
The password property in the HostConnectSpec object requires a clear-text password.
That means you would have to use the method Robert provided in that post.
I attached a file (since the forum SW doesn't like square brackets) with your script adapted for that method.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome, exactly what I was looking for. Thanks for your help!!