David2021
Contributor
Contributor

Automation to enabled services provisioning on vmkernel

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

0 Kudos
15 Replies
LucD
Leadership
Leadership

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


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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)

} 

 


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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)
} 


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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)
}


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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)
}

 


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

That was a typo, I corrected the code above.


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

0 Kudos
David2021
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

1. What is "not accurate"?


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

0 Kudos
David2021
Contributor
Contributor

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

Thanks a lot for your help.

0 Kudos
LucD
Leadership
Leadership

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.



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

0 Kudos