VMware Cloud Community
David2021
Contributor
Contributor

Automation to remove standard switch on several ESXi hosts

Hello,

I need some help to script with PowerCli to remove standard switch for several ESXi 6.7 server of a cluster. I use a list of esxi hostname with a cloumn name.

regards,

David

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

And which VSS?
All of them or are the names in the CSV?


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

 

yes VSS

yes names in CSV file

 

regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership

Could you provide the layout of that CSV file?
Is there a row for each VSS on each ESXi node?


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

 

In the CSV file it's compose with a unique column:

Name

esxi1

esx2

esx3

etc...

 

It's the same VSS name on each ESX.

 

regards

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this

$vssName = 'vss'

Import-Csv -Path .\names.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    Get-VMHost -Name $row.Name |
    Get-VirtualSwitch -Name $vssName |
    Remove-VirtualSwitch -Confirm:$false
}


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

Reply
0 Kudos
David2021
Contributor
Contributor

Can I use this type of script?

$StandardSwitch = Get-VirtualSwitch -Name $stdswitch
$listesxi = ".\$CSV"
$ESXi = Import-CSV $listesxi

foreach ($hostname in $ESXi) {

Get-VMHost -Name $hostname.Name | Get-VirtualSwitch -Name $StandardSwitch | Remove-VirtualSwitch -Confirm:$false

}

 

regards

Reply
0 Kudos
LucD
Leadership
Leadership

Sure, you can do whatever you want.
But I'm wondering, what is wrong with the snippet I gave earlier?


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

 

Nothing. All is OK.

 

Thanks for your help.

 

regards,

Reply
0 Kudos