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.
$profile = Get-VMHostProfile -Name testProfile
$additionalConfiguration = Apply-VMHostProfile -ApplyOnly -Profile $profile -Entity 10.23.114.166
$additionalConfiguration['network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.address'] = '10.0.0.128'
$additionalConfiguration['network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.subnetmask'] = '255.255.255.0'
Apply-VMHostProfile -ApplyOnly -Profile $profile -Entity 10.23.114.166 -Variable $additionalConfiguration
Sadly if you tried to execute the above you would get the following error.
PS > $additionalConfiguration['network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.Ip
AddressPolicy.address'] = "10.52.8.11"
Array assignment to [network.hostPortGrou ..] failed: Cannot convert value "network.hostPortGroup["key-vim-profile-
host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.address" to type "System.Int32". Error: "Input string
was not in a correct format.".
At line:1 char:26
+ $additionalConfiguration[ <<<< '"network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipCo
nfig.IpAddressPolicy.address'] ='10.52.8.11'
+ CategoryInfo : InvalidOperation: (10.52.8.11:String) [], RuntimeException
+ FullyQualifiedErrorId : ArrayAssignmentFailed
|
At first this may appear a little cryptic, but it get’s a lot clearer once we inspect the object types in use.
PS > $additionalConfiguration.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Object
PS > $additionalConfiguration[0]
Name Value
---- -----
network.hostPortGroup["key-...
PS > $additionalConfiguration[0].GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DictionaryEntry System.ValueType
|
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>
$VMHostProfile = Get-VMHostProfile -Name testProfile
$additionalConfiguration = Apply-VMHostProfile -ApplyOnly -Profile $VMHostProfile -Entity 10.23.114.166
($additionalConfiguration | Where-Object {$_.Name -eq 'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.address'}).Value = '10.0.0.128'
($additionalConfiguration | Where-Object {$_.Name -eq 'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.subnetmask'}).Value = '255.255.255.0'
Apply-VMHostProfile -ApplyOnly -Profile $VMHostProfile -Entity 10.23.114.166 -Variable $additionalConfiguration
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.
$VMHostProfile = Get-VMHostProfile -Name testProfile
$additionalConfiguration = @{
'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.address' = '10.0.0.128'
'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-VMkernel"].ipConfig.IpAddressPolicy.subnetmask' = '255.255.255.0'
}
Apply-VMHostProfile -ApplyOnly -Profile $VMHostProfile -Entity 10.23.114.166 -Variable $additionalConfiguration
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