PowerCLI: Apply-VMHostProfile passing parameters via $AdditionalConfiguration

I’ve ran across this particular issue myself, and submitted a bug to the PowerCLI team, but shortly after Andrew posted his ESXi 4.0 autoinstall Tim asked about this very issue.  There is a documentation error in Example #5 from the Apply-VMHostProfile cmdlet help.  Which contains the following code example.

Sadly if you tried to execute the above you would get the following error.

At first this may appear a little cryptic, but it get’s a lot clearer once we inspect the object types in use.

The example from the help docs was apparently expecting a Hashtable to be returned from apply-VMhostProfile.  Instead we found an array of DictionaryEntry objects… hence the error.

There are two possible work around’s we can employ until the PowerCLI team ships a fix.  The first one is complicated, but dynamic.

<pre class=’PowerShellColorizedScript’><span style=’color:#ff4500′>$profile</span> <span style=’color:#a9a9a9′>=</span> <span style=’color:#0000ff’>Get-VMHostProfile</span> <span style=’color:#000080′>-Name</span> <span style=’color:#8a2be2′>testProfile</span>

<span style=’color:#ff4500′>$additionalConfiguration</span> <span style=’color:#a9a9a9′>=</span> <span style=’color:#0000ff’>Apply-VMHostProfile</span> <span style=’color:#000080′>-ApplyOnly</span> <span style=’color:#000080′>-Profile</span> <span style=’color:#ff4500′>$profile</span> <span style=’color:#000080′>-Entity</span> <span style=’color:#8a2be2′>10.23.114.166</span>
<span style=’color:#000000′>(</span><span style=’color:#ff4500′>$additionalConfiguration</span> <span style=’color:#a9a9a9′>|</span> <span style=’color:#0000ff’>Where-Object</span> <span style=’color:#000000′>{</span><span style=’color:#ff4500′>$_</span><span style=’color:#a9a9a9′>.</span><span style=’color:#000000′>Name</span> <span style=’color:#a9a9a9′>-eq</span> <span style=’color:#8b0000′>’network.hostPortGroup[“key-vim-profile-host-HostPortgroupProfile-VMkernel”].ipConfig.IpAddressPolicy.address'</span><span style=’color:#000000′>}</span><span style=’color:#000000′>)</span><span style=’color:#a9a9a9′>.</span><span style=’color:#000000′>Value</span> <span style=’color:#a9a9a9′>=</span> <span style=’color:#8b0000′>’10.0.0.128′</span>
<span style=’color:#000000′>(</span><span style=’color:#ff4500′>$additionalConfiguration</span> <span style=’color:#a9a9a9′>|</span> <span style=’color:#0000ff’>Where-Object</span> <span style=’color:#000000′>{</span><span style=’color:#ff4500′>$_</span><span style=’color:#a9a9a9′>.</span><span style=’color:#000000′>Name</span> <span style=’color:#a9a9a9′>-eq</span> <span style=’color:#8b0000′>’network.hostPortGroup[“key-vim-profile-host-HostPortgroupProfile-VMkernel”].ipConfig.IpAddressPolicy.subnetmask'</span><span style=’color:#000000′>}</span><span style=’color:#000000′>)</span><span style=’color:#a9a9a9′>.</span><span style=’color:#000000′>Value</span> <span style=’color:#a9a9a9′>=</span> <span style=’color:#8b0000′>’255.255.255.0′</span>

<span style=’color:#0000ff’>Apply-VMHostProfile</span> <span style=’color:#000080′>-ApplyOnly</span> <span style=’color:#000080′>-Profile</span> <span style=’color:#ff4500′>$profile</span> <span style=’color:#000080′>-Entity</span> <span style=’color:#8a2be2′>10.23.114.166</span> <span style=’color:#000080′>-Variable</span> <span style=’color:#ff4500′>$additionalConfiguration</span></pre>

I actually don’t like this approach even though it’s a modified version of the included example.  I prefer just a simple static Hashtable.

All in all, the HostProfile cmdlets are surprisingly complete, and I think the majority of the “issues” I’ve ran across are a result of the SDK itself.  The Host Profiles sections of the API just don’t have the same fit and finish I’ve come to expect in a VMware API.

I’m sure carter and team will have this fixed in the next release, untill then…

~Glenn

1 thought on “PowerCLI: Apply-VMHostProfile passing parameters via $AdditionalConfiguration”

  1. Glenn,

    Thanks for the response. Maybe I am missing the obvious, but to the point of using your hashtable example, it didn’t work for me. The following now returns an invalid argument error. I tried both of your examples and do get the same error below.

    $profile = Get-VMHostProfile -Name WP-ESX4-Prod

    $additionalConfiguration = @{
    ‘network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.address’ = ‘10.0.0.128’
    ‘network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.subnetmask’ = ‘255.255.255.0’
    }
    # or this

    #$additionalConfiguration = Apply-VMHostProfile -ApplyOnly -Profile $profile -Entity sdwvsh106.albertsons.com
    #($additionalConfiguration | Where-Object {$_.Name -eq ‘network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.address’}).Value = ‘10.0.0.128’
    #($additionalConfiguration | Where-Object {$_.Name -eq ‘network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.subnetmask’}).Value = ‘255.255.255.0’

    Apply-VMHostProfile -ApplyOnly -Profile $profile -Entity $destvmhost -Variable $additionalConfiguration -Confirm:$False

    ERROR:
    Apply-VMHostProfile : 4/12/2010 10:10:50 AM Apply-VMHostProfile B72BF9DC-5D8E-4703-BC2D-BCE2DE
    vHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.Ip
    vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.
    At Z:scriptspowershelltestAdd_ESXi4_to_VC.ps1:367 char:20
    + Apply-VMHostProfile <<< $additionalConfiguration.GetType()

    IsPublic IsSerial Name BaseType
    ——– ——– —- ——–
    True True Hashtable System.Object

    and

    [vSphere PowerCLI] Z:scriptspowershelltest> $additionalConfiguration | fl *

    Name : network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.subnetmask
    Key : network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.subnetmask
    Value : 255.255.255.0

    Name : network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.address
    Key : network.dvHostNic[“key-vim-profile-host-DvsHostVnicProfile-dvSwitch_WP-dvPG-NFS-VMotion-vmotion”].ipConfig.IpAddressPolicy.address
    Value : 10.0.0.128

    btw, I replaced my IP’s above with 10.0.0.128.

    Regards,
    Tim

Leave a Reply