VMware Cloud Community
sspikent
Enthusiast
Enthusiast
Jump to solution

New-VDSwitch - Can I ask vCenter, what versions are supported

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."

1 Solution

Accepted Solutions
dtaliafe
Hot Shot
Hot Shot
Jump to solution

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.

View solution in original post

7 Replies
dtaliafe
Hot Shot
Hot Shot
Jump to solution

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.

LucD
Leadership
Leadership
Jump to solution

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:

New-VDSwitch -Name dummy -Version 1.0 -Location Datacenters -ErrorAction SilentlyContinue

$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

sspikent
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And from where do you get the supported versions?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
sspikent
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

Using a little trial and error, I found it with:

$DvSwitchManager = Get-View $global:DefaultVIServer.ExtensionData.Content.DvSwitchManager

$DvSwitchManager.QueryAvailableDvsSpec()

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should be

$DvSwitchManager.QueryAvailableDvsSpec($true)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

sspikent
Enthusiast
Enthusiast
Jump to solution

Of course, else if I created a 4.1.0 - I can deploy but I get an 'unsupported version'.

Thanks Luc!

Reply
0 Kudos