I’m dealing with many clusters of stateless hosts deployed via vSphere AutoDeploy and updating host profiles from reference host is something I badly needed. I was surprised this cmdlet didn’t exist so I wrote a function to do the job. Hope folks find this useful.
Function Update-VMHostProfile {
<#
.SYNOPSIS
Updates the host profile from its reference host.
.DESCRIPTION
The Update-VMHostProfile updates a host profile from its reference host.
.PARAMETER Profile
Specify the host profile in which you wish to update from reference host.
.EXAMPLE
C:\PS> Update-VMHostProfile -Profile $Profile
Updates the host profile $Profile from its reference host.
.EXAMPLE
C:\PS> Get-VMHost -Name $Host | Get-VMHostProfile | Update-VMHostProfile
Get's the host profile attached to the VMHost $Host and updates it from the host profile's reference host.
.EXAMPLE
C:\PS> Get-VMHostProfile | Update-VMHostProfile
Updates all host profiles from reference host.
.NOTES
Function has only been tested with vSphere 5.1, should work with vSphere 5.0.
.LINK
http://infrastructureadventures.com/
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
$Profile
)
BEGIN {}
PROCESS {
if ( ($Profile.GetType()).name -eq "String" ) {
$Profile = Get-VMHostProfile -Name $Profile
}
$HostProfileReferenceHostId = ("host-" + (($Profile.ReferenceHost.Id).split("-"))[2])
$HostProfileHostBasedConfigSpec = New-Object VMware.Vim.HostProfileHostBasedConfigSpec
$HostProfileHostBasedConfigSpec.host = New-Object VMware.Vim.ManagedObjectReference
$HostProfileHostBasedConfigSpec.host.type = "HostSystem"
$HostProfileHostBasedConfigSpec.host.Value = $HostProfileReferenceHostId
$HostProfileHostBasedConfigSpec.useHostProfileEngine = $true
$HostProfileView = Get-View -Id $Profile.Id
$HostProfileView.UpdateHostProfile($HostProfileHostBasedConfigSpec)
$Profile
}
END {}
}
very awesome! I think lots of people need this.
Comment by vmjfk — 09/25/2012 @ 8:26 AM
This is an awesome blog, really like the clear examples.
Comment by Magnus — 10/22/2012 @ 1:14 PM