PowerCLI

 View Only
Expand all | Collapse all

Automation to enabled services provisioning on vmkernel

  • 1.  Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 10:23 AM

    Hello,

    I need some help to script with PowerCli to tick the box provisioning on Enabled services on a specific VMkernel for several ESXi 6.7 server of a cluster.

    regards,

    David



  • 2.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 10:34 AM

    Which TCP/IP stack?
    Default or a custom one?



  • 3.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 10:39 AM

    Hello,

    I leave TCP/IP stack with "Default". I want just to tick the box Provisioning on Enabled services list for a VMkernel.

    regards,

    David



  • 4.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 11:44 AM

    Try something like this (update the clustername and vmkname)

    $clusterName = 'cluster'
    $vmkName = 'vmk0'
    
    
    Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $vmkMgr = Get-View -Id $esx.ExtensionData.ConfigManager.VirtualNicManager
        $vmkMgr.SelectVnicForNicType('vSphereProvisioning',$vmkName)
    
    } 
    

     



  • 5.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 11:54 AM

    Thanks for your feedback LucD.

    If I use a file CSV with ESXi hostname because I want specific ESXi with provisioning services and not all.

    What do you suggest regarding your script?

     

    regards,

    David



  • 6.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 11:57 AM

    If that CSV file has a column with the name 'vmhostname', you could do

    Import-Csv -Path .\hostnames.csv -UseCulture -PipelineVariable row |
    ForEach-Object -Process {
        $esx = Get-VMHost -Name $row.VMHostName
        $vmkMgr = Get-View -Id $esx.ExtensionData.ConfigManager.VirtualNicManager
        $vmkMgr.SelectVnicForNicType('vSphereProvisioning',$vmkName)
    } 
    


  • 7.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 01:56 PM

    Thanks for your return LucD

    Can I use this type of script?

    $vmkName = 'vmk0'
    $listesxi = ".\$CSV"
    $ESXi = Import-CSV $listesxi

    foreach ($hostname in $ESXi) {

    $vmkMgr = Get-View -Id $hostname.Name.ExtensionData.ConfigManager.VirtualNicManager
    $vmkMgr.SelectVnicForNicType('vSphereProvisioning',$vmkName)

    }

     

    regards,

    David



  • 8.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 22, 2021 02:16 PM

    There are a few issues in that snippet.
    You have to work with the object returned by Get-VMHost.
    To reference the hostname in that CSV, you have to mention the columnname.

    $vmkName = 'vmk0'
    $listesxi = ".\$CSV"
    $ESXi = Import-CSV $listesxi
    
    foreach ($esx in (Get-VMHost -Name $ESXi.Hostname)) {
        $vmkMgr = Get-View -Id $esx.ExtensionData.ConfigManager.VirtualNicManager
        $vmkMgr.SelectVnicForNicType('vSphereProvisioning',$vmkName)
    }
    


  • 9.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 09:32 AM

    Hello,

    I have 2 points:

    1/ When I have written vmk name variable because I'm not sure that is the same VMK number device for each esx but sure of the PortgroupName:

    $vmkName = Get-VMHostNetworkAdapter -vmkernel | ?{$_.PortgroupName -eq "test_provisioning"} | select Name (or I try with DeviceName)

    But when I launch the script to activate the provisioning, I have an error: "A specified parameter was not correct:" without more explanation on vSphere console. It seems not catch the vmk number device with my variable $vmkName.

    2/ with this: foreach ($esx in (Get-VMHost -Name $hostname.Name)) {

    Log -Message "Activate Provisioning for $($hostname.Name)"

    $hostname.Name give all the entire list of esxi hostname of the csv file display on screen and in the log for each activation provisioning service. But I don't know which hostname is concern by provisioning activation. I would like only a hostname concern for each action of provisioning activation.


    regards,
    David



  • 10.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 09:40 AM

    Try like this

     

    $listesxi = ".\$CSV"
    $ESXi = Import-CSV $listesxi
    
    foreach ($esx in Get-VMHost -Name $ESXi.Hostname) {
        Log -Message "Activate Provisioning for $($esx.Name)"
        $vmkName = Get-VMHostNetworkAdapter -VMHost $esx -VMKernel -PortGroup 'test_provisioning' |
            select -ExpandProperty Name
        $vmkMgr = Get-View -Id $esx.ExtensionData.ConfigManager.VirtualNicManager
        $vmkMgr.SelectVnicForNicType('vSphereProvisioning',$vmkName)
    }
    

     



  • 11.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 09:54 AM

    ello,

    Thanks for your return

    Concerning this variable:

    $vmkName = Get-VMHostNetworkAdapter -VMHost esx1* -VMKernel -PortGroup 'test_provisioning' | select -ExpandProperty Name

    Have I to choose? between: -VMHost esx1* -VMKernel -PortGroup

    What is representing esx1* ?

    regards,
    David



  • 12.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 09:59 AM

    That was a typo, I corrected the code above.



  • 13.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 10:41 AM

    Hello,

    thanks of your clarification. It's working now as expected.

    notice:

    1/ $vmkName = Get-VMHostNetworkAdapter -VMHost $esx -VMKernel -PortGroup 'test_provisioning' | select -ExpandProperty Name

    >> The bad point is the time needed to activate for one provisioning activation around 1mn10s by host. I don't know why is so long. I tested the script with this variable for 5 hosts it's took 5mn31s !! and it's not accurate and not recommended for automation

     

    2/ $vmkName = 'vmkxx'

    The time is very fast if I put the 'vmkxx' as the variable $vmkname. It's took 6 seconds for 5 ESXi



  • 14.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 10:45 AM

    1. What is "not accurate"?



  • 15.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 10:56 AM

    The time 1mn10s is not accurate relevant for automation because it's more longer than operate manually.

    Thanks a lot for your help.



  • 16.  RE: Automation to enabled services provisioning on vmkernel

    Posted Feb 23, 2021 10:59 AM

    I suspect you will have to examine your environment.
    I just did the same and it takes 0.3 seconds to enable the service on a vmk.