Automation

 View Only
  • 1.  Update Host Profiles with PowerCLI

    Posted Jan 05, 2012 11:54 AM

    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



  • 2.  RE: Update Host Profiles with PowerCLI

    Posted Jan 05, 2012 01:14 PM

    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.



  • 3.  RE: Update Host Profiles with PowerCLI
    Best Answer

    Posted Jan 05, 2012 02:09 PM

    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



  • 4.  RE: Update Host Profiles with PowerCLI

    Posted Jan 05, 2012 03:37 PM

    Hi Luc,

    thank you so much, this is exactly what I needed.

    Regards,

    Harold