Automation

 View Only
  • 1.  New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Mar 28, 2019 11:45 AM

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



  • 2.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported
    Best Answer

    Posted Mar 28, 2019 02:31 PM

    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.



  • 3.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Apr 02, 2019 11:32 AM

    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



  • 4.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Apr 02, 2019 11:34 AM

    And from where do you get the supported versions?



  • 5.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Apr 03, 2019 09:11 AM

    Hi Luc,

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

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

    $DvSwitchManager.QueryAvailableDvsSpec()



  • 6.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Apr 03, 2019 09:43 AM

    That should be

    $DvSwitchManager.QueryAvailableDvsSpec($true)



  • 7.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Apr 03, 2019 09:48 AM

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

    Thanks Luc!



  • 8.  RE: New-VDSwitch - Can I ask vCenter, what versions are supported

    Posted Mar 28, 2019 06:12 PM

    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