Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 189307

Re: Removing Network Adapters from Powered On VM's

$
0
0

Robert, I worked your script a bit to try and remove all NIC's with a certain port group name (e.g. an entire VLAN) and ended up with the following:

 

$VMs = Get-VM test*

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "remove"

 

$NICs = "Network Adapter 1","Network Adapter 2","Network Adapter 3","Network Adapter 4","Network Adapter 5"

$i = 0

 

foreach($VM in $VMs){

    $Adapters = Get-NetworkAdapter -VM $VM|?{$_.NetworkName -like "dummy"}

    foreach($Adapter in $Adapters){

        while ($i -le 4){

            if($Adapter -like $NICs[$i]){

                $spec.deviceChange[0].device = $VM.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $NICs[$i]}

                $VM.ExtensionData.ReconfigVM_Task($spec)

                $i++

            }

            else{

                $i++

            }

        }

    }

}

 

Probably not the prettiest code, but since $_.DeviceInfo.Lable is mandatory I couldn't switch it to $_.DeviceInfo.Summary -eq "Dummy".

However, above code only removes one NIC, for some reason the loop seems to end after first "hit". Can you see what I'm missing?


Viewing all articles
Browse latest Browse all 189307

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>