I'm writing a script to create new VDSwitches based on a predefined set of standards. In order to try and future-proof the script, I'd like to set it to create the highest version number supported by the environment by default.
The message from PowerCli, clearly shows that this is defined, how do I get this list, without having to first deliberately generate the error and parsing the data from the error message?
"New-VDSwitch You have specified invalid VDSwitch version. Valid versions are 4.0,4.1.0,5.0.0,5.1.0,5.5.0,6.0.0,6.5.0."
If you don't specify a version I'm pretty sure it will automatically use the highest version that is supported for the vCenter you are creating the VDS in.
If you don't specify a version I'm pretty sure it will automatically use the highest version that is supported for the vCenter you are creating the VDS in.
Afaik that info is not readily available through an API or cmdlet.
But we can extract the accepted values by provoking the error message, and extracting the values.
Select-String is your friend :smileygrin:
$validVersion = ($error[0].exception.message -replace "\.\s*$").Substring($t.IndexOf('are ') + 4).TrimEnd('.') |
Select-String -Pattern "([\d\.]+)" -AllMatches | % { $_.Matches | % { $_.Groups[1].Value } }
$validVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. I had a couple of days off. Sometimes, I find that sometimes I look for the solution in the most complicated places!
Easier with your suggestion:
($SwitchVersion and $SwitchNotes as optional script parameters)
$SwitchParams = @{
Server = $vCenter
Name = $SwitchName
Location = $Location
NumUplinkPorts = $NumUplinks
Mtu = $DefaultMtu
LinkDiscoveryProtocol = $LinkDiscoveryProtocol
LinkDiscoveryProtocolOperation = $LinkDiscoveryProtocolOperation
}
if ($SwitchVersion) {$SwitchParams.Add('Version',$SwitchVersion)}
if ($SwitchNotes) {$SwitchParams.Add('Notes',$SwitchNotes)}
$VDSwitch = New-VDSwitch @SwitchParams
Simples!
Steve
And from where do you get the supported versions?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Using a little trial and error, I found it with:
$DvSwitchManager = Get-View $global:DefaultVIServer.ExtensionData.Content.DvSwitchManager
$DvSwitchManager.QueryAvailableDvsSpec()
That should be
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Of course, else if I created a 4.1.0 - I can deploy but I get an 'unsupported version'.
Thanks Luc!