Hi there,
We are using a lot of Host Profiles for a lot of clusters....
Now we have to update the adminstrator password and setting in each and every host profile.
Host Profile | Security Configuration | Administrator Password | Configure a fixed administrator password
Is there any way to do this in an automated way?
Thanks and kind regards,
Harold
Try this. I was able to change the administrator password this way.
function Copy-Property ($From, $To, $PropertyName ="*") { foreach ($p in Get-Member -In $From -MemberType Property -Name $propertyName) { trap { Add-Member -In $To -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force continue } $To.$($P.Name) = $From.$($P.Name) } } $hostProfileName = "MyHostProfile" $newAdminPswd = "newpswd" $hp = Get-VMHostProfile -Name $hostProfileName $spec = New-Object VMware.Vim.HostProfileCompleteConfigSpec Copy-Property -From $hp.ExtensionData.Config -To $spec $secpol = New-Object VMware.Vim.ProfilePolicy $secpol.Id = "AdminPasswordPolicy" $secpol.PolicyOption = New-Object VMware.Vim.PolicyOption $secpol.PolicyOption.Id = "FixedAdminPasswordOption" $secpol.PolicyOption.Parameter += New-Object VMware.Vim.KeyAnyValue $secpol.PolicyOption.Parameter[0].Key = "password" $secpol.PolicyOption.Parameter[0].Value = New-Object VMware.Vim.PasswordField $secpol.PolicyOption.Parameter[0].Value.Value = $newAdminPswd $spec.ApplyProfile.Security.Policy = @($secpol) $hp.ExtensionData.UpdateHostProfile($spec)
The script uses the Copy-Property function from Dennis Verwiej to copy the HostProfileConfigInfo object to the HostProfileCompleteConfigSpec object
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm afraid the current Host Profile cmdlets don't offer that functionality.
But I assume that this change could be done with the UpdateHostProfile method.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try this. I was able to change the administrator password this way.
function Copy-Property ($From, $To, $PropertyName ="*") { foreach ($p in Get-Member -In $From -MemberType Property -Name $propertyName) { trap { Add-Member -In $To -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force continue } $To.$($P.Name) = $From.$($P.Name) } } $hostProfileName = "MyHostProfile" $newAdminPswd = "newpswd" $hp = Get-VMHostProfile -Name $hostProfileName $spec = New-Object VMware.Vim.HostProfileCompleteConfigSpec Copy-Property -From $hp.ExtensionData.Config -To $spec $secpol = New-Object VMware.Vim.ProfilePolicy $secpol.Id = "AdminPasswordPolicy" $secpol.PolicyOption = New-Object VMware.Vim.PolicyOption $secpol.PolicyOption.Id = "FixedAdminPasswordOption" $secpol.PolicyOption.Parameter += New-Object VMware.Vim.KeyAnyValue $secpol.PolicyOption.Parameter[0].Key = "password" $secpol.PolicyOption.Parameter[0].Value = New-Object VMware.Vim.PasswordField $secpol.PolicyOption.Parameter[0].Value.Value = $newAdminPswd $spec.ApplyProfile.Security.Policy = @($secpol) $hp.ExtensionData.UpdateHostProfile($spec)
The script uses the Copy-Property function from Dennis Verwiej to copy the HostProfileConfigInfo object to the HostProfileCompleteConfigSpec object
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
thank you so much, this is exactly what I needed.
Regards,
Harold