I am getting a couple of errors I was hoping to get some opinions on.
License Section:
In my script I get an entityId error when the licensing section runs, but if I try this same syntax without the variables by typing directly into the PS window - it executes fine.
foreach ($vmhost in $vmhost_array) {
Write-Host "Adding New Host - " $vmhost "to vCenter..."
Add-VMHost $vmhost -Location $cluster -User $user -Password $passwd -RunAsync -force:$true | Out-Null
Write-Host "Adding License to New Host - " $vmhost "..."
Set-VMHost -VMHost $vmhost -LicenseKey $esx_license | Out-Null
}
Set-VMHost : 11/18/2017 5:56:54 PM Set-VMHost A specified parameter was not correct: entityId
At C:\Documents\PowerCLI\Config.ps1:24 char:1
+ Set-VMHost -VMHost $vmhost -LicenseKey $esx_license | Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VMHost], InvalidArgument
+ FullyQualifiedErrorId : ViCore_ComputeResourceServiceImpl_UpdateHostLicense_ServerError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVMHost
DVUplink Section:
I get the error for this section of the script but it actually configures the port groups as expected. I have also noticed that if a DVSwitch is created via GUI the uplinks are named "Uplink 1" and "Uplink 2" respectively but if the DVSwitch is created via PowerCLI then the uplinks are named "dvUplink1" and "dvUplink2" respectively. Any thoughts on whats causing the false positive? Or is it even a false positive?
Write-Host "Creating vMotion Port Group for" $vds_name "..."
New-VDPortgroup -VDSwitch $vds_name -Name $esx_vmotion_PG -VlanId 6 | Out-Null
Write-Host "Setting vMotion Port Group Teaming Policy..."
Get-VDPortgroup $esx_vmotion_PG | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink1" -StandbyUplinkPort "dvUplink2" -UnusedUplinkPort "dvUplink3","dvUplink4" -LoadBalancingPolicy ExplicitFailover | Out-Null
Set-VDUplinkTeamingPolicy : 11/18/2017 5:57:35 PM Set-VDUplinkTeamingPolicy A specified parameter was not correct: spec.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort. The activeUplink
PortName value :
dvUplink1 is not valid in the spec.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort.
At C:\Documents\PowerCLI\Config.ps1:51 char:64
+ ... ingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VDUplinkTeamingPolicy], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Vds.Commands.Cmdlets.SetVDUplinkTeamingPolicy
I was able to replicate the error you are seeing on the teaming policy.
When I have a portgroup with the same name on another VDS, I get the exact same error. The error is for the other portgroup, and the configuration is applied on the new portgroup on the new VDS.
To avoid that, explictely specify the VDS.
Like this
Get-VDPortgroup $esx_vmotion_PG -VDSwitch $vds_name | Get-VDUplinkTeamingPolicy |
Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink1,dvUplink2 -UnusedUplinkPort dvUplink3,dvUplink4
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Which PowerCLI version are you using?
And which vSphere/ESXi version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI 6.5.1 build 5377412
vSphere 6.5U1
Both code snippets seem to be working for me.
1) Since you add the ESXi node, perhaps it would be better to wait (in a loop) till the ESXi node is marked as "connected" before taking any further actions on it?
2) I can only simulate that behaviour when I use the incorrect uplinkname, and that is also what the error message seems to suggest.
As a test, you check if the uplinkname you are using is present in the list of uplinkportnames.
$vdsName = 'MyVds'
Get-VDSwitch -Name $vdsName | Get-VDPortgroup | where{$_.IsUplink} | Get-VDPort | select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1) I'm not sure how to do a wait condition, so I may just create a separate loop for setting the licenses and just add all the hosts followed by adding all the licenses. Is one method typically recommended over the other?
2) Here is the output of the Uplinks on this switch...crazy right?
Name
----
dvUplink4
dvUplink3
dvUplink2
dvUplink1
dvUplink4
dvUplink3
dvUplink2
dvUplink1
1) For the wait loop you could do something simple like
Add-VMHost $vmhost -Location $cluster -User $user -Password $passwd -RunAsync -force:$true | Out-Null
$esx = Get-VMHost -Name $vmhost
while($esx.State -ne 'Connected'){
sleep 2
$esx = Get-VMHost -Name $vmhost
}
Set-VMHost -VMHost $esx -LicenseKey $esx_license | Out-Null
Or eventually leave out the RunAsync switch on the Add-VMHost.
2) Did you check that the active uplink you specify is also one of the uplinks that is used by the connected ESXi nodes?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1) I'll remove the Async and see what happens then do the wait loop if I still run into issues.
2) So what I am doing with the Uplinks is creating the DVSwitch with 4 uplinks then assigning the port groups to the DVSwitch to setup a specific teaming policy as the port groups are created. So in this scenario there are not actual vmnics associated to them yet - so that as the hosts vmnics are added to the DVSwitch they will inherit the portgroup teaming policies. It's assigning them correctly I just get an error for every port group created.
# Create VDS
Write-Host "Creating new VDS" $vds_name "..."
$vds = New-VDSwitch -Name $vds_name -Location $datacenter -NumUplinkPorts 4 -Mtu 9000
## Set Network IO Control to Enabled on VDS
Write-Host "Setting Network IO Control to" $vds_name "..."
(get-vdswitch $vds_name | get-view).EnableNetworkResourceManagement($true)
### Start Creating VDS Port Groups###
## Management Port Group
Write-Host "Creating Management Port Group for" $vds_name "..."
New-VDPortgroup -VDSwitch $vds_name -Name $esx_mgmt_PG -VlanId 5 | Out-Null
Write-Host "Setting Management Port Group Teaming Policy..."
Get-VDPortgroup $esx_mgmt_PG | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink1,dvUplink2 -UnusedUplinkPort dvUplink3,dvUplink4 -LoadBalancingPolicy LoadBalanceSrcId | Out-Null
I was able to replicate the error you are seeing on the teaming policy.
When I have a portgroup with the same name on another VDS, I get the exact same error. The error is for the other portgroup, and the configuration is applied on the new portgroup on the new VDS.
To avoid that, explictely specify the VDS.
Like this
Get-VDPortgroup $esx_vmotion_PG -VDSwitch $vds_name | Get-VDUplinkTeamingPolicy |
Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink1,dvUplink2 -UnusedUplinkPort dvUplink3,dvUplink4
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah! Yep that makes complete sense, thanks as usual!