Hello
below script worked well for my vcenter 5.1 & vcenter 5.5 based hosts.
Get-VMHost -location xxx |sort | where{$excludeServers -notcontains $_.Name.Split('.')[0]} | %{
Connect-VIServer -Server $_.Name -User root -Password $currentPswd | Out-Null
Write-host "Connected to $_"
Set-VMHostAccount -UserAccount root -Password $newPswd -Confirm:$false | Out-Null
Write-host "passwd change for root account on host to $_"
Disconnect-VIServer -Server $_.Name -Confirm:$false
Write-host "Disconnected from $_"
}
But i got err in vcenter 6.x servers . passwd is not issue.
I got below err
Set-VMHostAccount : 6/19/2016 4:12:36 PM | Set-VMHostAccount | At least one element in the source array could |
not be cast down to the destination array type.
Any suggestions.
Can you try like this ?
Get-VMHost -location xxx |sort | where{$excludeServers -notcontains $_.Name.Split('.')[0]} | %{
Connect-VIServer -Server $_.Name -User root -Password $currentPswd | Out-Null
Write-host "Connected to $_"
Get-VMHostAccount -User root |
Set-VMHostAccount -Password $newPswd -Confirm:$false | Out-Null
Write-host "passwd change for root account on host to $_"
Disconnect-VIServer -Server $_.Name -Confirm:$false
Write-host "Disconnected from $_"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i Also have below set
$multiState
= (
Get-PowerCLIConfiguration
).DefaultVIServerMode
$warnings
= (
Get-PowerCLIConfiguration
).DisplayDeprecationWarnings
Set-PowerCLIConfiguration
-DefaultVIServerMode
Multiple
-Confirm
:
$false
-DisplayDeprecationWarnings
:
$false
|
Out-Null
Can you try like this ?
Get-VMHost -location xxx |sort | where{$excludeServers -notcontains $_.Name.Split('.')[0]} | %{
Connect-VIServer -Server $_.Name -User root -Password $currentPswd | Out-Null
Write-host "Connected to $_"
Get-VMHostAccount -User root |
Set-VMHostAccount -Password $newPswd -Confirm:$false | Out-Null
Write-host "passwd change for root account on host to $_"
Disconnect-VIServer -Server $_.Name -Confirm:$false
Write-host "Disconnected from $_"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is what i did finally tho
foreach ($line in $csv)
{
Connect-VIServer -Server $($line.esxi) -User "root" -Password $currentPswd -WarningAction silentlyContinue
Set-VMHostAccount -UserAccount root -Password $newPswd -Confirm:$false | Out-Null
Disconnect-VIServer -Server $($line.esxi) -Confirm:$false
}