Infrastructure Adventures


Update vSphere Host Profile from Reference Host via PowerCLI

Filed under: Virtualization — Tags: , , , — Joe Keegan @ 7:18 PM

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 {
		Updates the host profile from its reference host.		
		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.
		C:\PS> Update-VMHostProfile -Profile $Profile

		Updates the host profile $Profile from its reference host.

		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.
		C:\PS> Get-VMHostProfile | Update-VMHostProfile

		Updates all host profiles from reference host.

			Function has only been tested with vSphere 5.1, should work with vSphere 5.0.


	Param (


		if ( ($Profile.GetType()).name -eq "String" ) {
			$Profile = Get-VMHostProfile -Name $Profile

		$HostProfileReferenceHostId = ("host-" + (($Profile.ReferenceHost.Id).split("-"))[2])
		$HostProfileHostBasedConfigSpec = New-Object VMware.Vim.HostProfileHostBasedConfigSpec
		$ = New-Object VMware.Vim.ManagedObjectReference
		$ = "HostSystem"
		$ = $HostProfileReferenceHostId
		$HostProfileHostBasedConfigSpec.useHostProfileEngine = $true

		$HostProfileView = Get-View -Id $Profile.Id

	END {}


Creating Host Profile Answer Files with PowerCLI

Filed under: Virtualization — Tags: , , , , , , , — Joe Keegan @ 10:41 PM

Recently I was involved in a project with the goal of completely automating the creation and configuration of a VMware cluster. Basically we wanted to point a script at an empty vCenter server & a UCS manager and 30 minutes later have a fully configured cluster ready to add to our cloud.

One of the hurdles we had implementing this automation was getting a host profile to apply automatically to a newly AutoDeployed ESXi host. This was mostly related to automatically generating an answer file for a particular host. Here are the lessons learned.

Configuring MAC Addresses for VMKs

When working with host profiles in the past I wouldn’t pay too much attention to the process when I applied a host profile to a host.  I would get to the screen that asked for the MAC address for a VMK and would mindless hit next. ESX always generated the MAC just fine and I never gave it much thought. Unfortunately you can’t ignore this when trying to setup the answer file via PowerCLI.

The default for this settings is Prompt the user for the MAC Address if no default is available, but this seems to always need input. Luckily Paul Whitman had posted over at his blog that if you change this setting for each of your VMKs to User must explicily choose  the policy option then the system will automatically generate the MAC addresses.  This has to be a bug (at least in 5.0.0/441354), the wording of the option just doesn’t make any sense to me and they didn’t even spell explicitly correctly!

When editing your Host Profile the MAC address specification for your VMKs can be found in one of two places.

  • Networking configuration –> Host Port Group –> Port-Group Name –> Determine how MAC address for vmknic should be decided
  • Networking configuration –> Host virtual NIC –>  vDS Name : Port-Group Name -> Determine how MAC address for vmknic should be decided

Specifying the IP Addresses in the Answer File

It doesn’t seem like there is a way to create an answer file with any of the defined cmdlets. The Apply-VMHostProfile cmdlet has a way to “Specify a hash table object that provides values for the host profile required variables.” by using -Variable. As far as I can tell this allows you to specify the answers the host profile needs to apply the profile, but it doesn’t create an answer file. This may not be too big of a deal for a stateful boot-from-disk ESXi server, since the config changes made by the host profile stick around, but for a stateless AutoDeployed ESXi server which needs the answers everytime, its no good.

So get-view to the rescue. Again, as luck would have it, most of the leg work was done by someone else and I found this script in the Vmware PowerCLI community that pointed me in the right direction.

I’ve adapted that script for my own needs. The community script provided the info from a CSV file, but I already had all the info in Arrays in my script. Here is the meat as something stand alone.

$targetHost = Get-VMHost -Name "ESXiHost"
$hostProfileManagerView = Get-View "HostProfileManager"
$answerFileCreateSpec = New-Object VMware.Vim.AnswerFileOptionsCreateSpec

$propPath = New-Object VMware.Vim.ProfilePropertyPath
$propPath.ProfilePath = 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-vDS-PG"].ipConfig'
$propPath.PolicyId = "IpAddressPolicy"

$addr = New-Object VMware.Vim.KeyAnyValue
$addr.key = "address"
$addr.value = "X.X.X.X"
$mask = New-Object VMware.Vim.KeyAnyValue
$mask.key = "subnetmask"
$mask.value = ""

$param = New-Object VMware.Vim.ProfileDeferredPolicyOptionParameter
$param.InputPath = $propPath
$param.Parameter += $addr
$param.Parameter += $mask
$answerFileCreateSpec.UserInput += $param

$hostProfileManagerView.UpdateAnswerFile($targetHost.ExtensionData.MoRef, $answerFileCreateSpec)

Lines 1 -3: Get the host object and create some needed objects to create the answer file. Replace the name on line 1 with the name of your host.

Lines 5-7: Define the path to the info in the answer file that you are going to provide. You will need to replace the vDS and PG with the information from your vDS. See below for info on how to get this information.

Lines 9 -14: Provide the IP information, make sure to update lines 11 and 14 with the correct IP and subnet information.

Lines 16 – 20: finish constructing the details for the answer file, no changes are needed in this section.

Line 22: Creates the answer file based on the provided information.

Obviously you would need to do this for every VMK you need to provide IP information.

You can also use the HostProfileManager object  (stored in $hostProfileManagerView in the example above) to check the host profile.


CheckedTime : 7/30/2012 1:05:37 AM
Host : HostSystem-host-5239
Status : valid
Error :
LinkedView :
DynamicType :
DynamicProperty :

You are looking for the Status of valid. If it’s invalid, then the answer file is not complete.

You can use the Get-VMHostProfileRequiredInput cmdlet to get the profile paths that you need to specify (i.e. what goes into line 6 of the above script) for the answer file configuration.

PS>Get-VMHostProfileRequiredInput -VMHost $VMHost -Profile $HostProfile | fl

Key : network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-vDS-PG"].ipConfig.IpAddressPolicy.address
Type : Required
VMHost :
VMHostProfile : HostProfile
Key : network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-vDS-PG"].ipConfig.IpAddressPolicy.subnetmask
Type : Required
VMHost :
VMHostProfile : HostProfile

Specifying the Root Password in the Answer File

The last part of the puzzle was setting the root password in the host profile. Since we were importing the host profile the root password is stripped from the host profile and it defaults to leaving the root password unchanged, which would be blank for the AutoDeployed host.

And for the third lucky find, it turns out LucD had already written a function called Set-VMHostProfileExtended that updates the root password stored in a host profile. Running this function against our imported host profile set the profile to update the root password and the password to the desired value.

Final Words

When I started this post I thought it would be nice to share a solution to a problem I was having. I didn’t realize it would mostly be just putting together solutions from three different people. But I guess that is what the Internet is all about and I’m glad they shared. Hopefully this post will save someone else the time it took for me to find and put these different components together.


3Par VAAI Plug-In and VMware Auto Deploy

Filed under: Storage, Virtualization — Tags: , , , , , , — Joe Keegan @ 10:36 AM

Just a quick post on using the HP 3PAR Software Plug-In for VMware VAAI with VMware Auto Deploy. The process should be pretty much the same for adding any other plugin.

1.) Download the VAAI 2.2 Plugin form HP

Get it here – HP 3PAR Software Plug-In for VMware VAAI (If the link is dead just Google for it)

2.) Load your depot & add the FDM

I use an offline depot so I load it and the FDM (VMware’s Failover Domain Manager – i.e. VMware HA).

Add-EsxSoftwareDepot <Offline Depot Path>
Add-EsxSoftwareDepot http://<vCenter Server>/vSphere-HA-depot
Add-EsxSoftwarePackage -ImageProfile "<ImageProfile>" -SoftwarePackage vmware-fdm

3.) Add the 3Par VAAI Plug-in

The Plug-in is located in a zip file, the one I downloaded from HP is called, yours should have the same or similar name. Then add the zip as a depot and and add the plug-in to your image profile.

Add-EsxSoftwareDepot C:\Depot\
Add-EsxSoftwarePackage -ImageProfile "<ImageProfile>" -SoftwarePackage 3PAR_vaaip_InServ

4. Create Deploy Rule

Create the deploy rule to use the image profile that includes the Plug-in.

New-DeployRule -Name <Rule Name> -Item "<ImageProfile>",<Host Profile>,<Cluster> -Pattern <Patern>
Add-DeployRule -DeployRule <Rule Name>

5. Edit the Host Profile

The ESXi server needs to know to load the plug-in and this is accomplished through the host profile applied to server.

Edit the host profile and drill down to Storage configuration –> Pluggable Storage Architecture (PSA) configuration –> PSA claimrule number  and then select Add Profile. This will add a psa_psaProfile_PsaClaimrulesProfile.

Expand the psa_psaProfile_PsaClaimrulesProfile to show the Claim information and the Claim type. Click on the Claim information and enter the following information.

That’s 5001 for Rule Number, VAAI_Filter for PSA plugin name and filter for claimrule class.

The click on claim type and enter the following.

That’s 3PARdata for the Vendor name and * for the Model.

Now create another psa_psaProfile_PsaClaimrulesProfile by right clicking and selecting add profile again. Enter the following for the Claim information.

That’s 5001 for Rule Number, 3PAR_VAAIP_INSERV for PSA plugin name and VAAI for claimrule class.

Then enter the same info you entered above for the Claim type. That’s 3PARdata for the Vendor name and * for the Model.

As an aside, I got this information by creating a host profile from an ESXi host that had the plugin installed and working. I looked through that host profile and pulled out this info.

Now hit OK to save the host profile and you should be good to go. Once you provision another host via Auto Deploy using this host profile you should see VAAI working for your 3PAR LUNs. You can check this by validating that Hardware Acceleration for these LUNs show supported.

The Silver is the New Black Theme. Blog at


Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: