VMware Cloud Community
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Disconnecting the NICs

Hi,

I have few VMs in text file located in 'D:\VMware\vms.txt'

I am using Windows 10.

Is it possible to disconnect all the NICs of that VMs from vCenter by a script?

Thanks in advance!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-VM -Name (Get-Content -Path D:\VMware\vms.txt) |

where{$_.Guest.OSFullName -match "Windows 10"} |

Get-NetworkAdapter |

Set-NetworkAdapter -Connected:$false -Confirm:$false


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-VM -Name (Get-Content -Path D:\VMware\vms.txt) |

where{$_.Guest.OSFullName -match "Windows 10"} |

Get-NetworkAdapter |

Set-NetworkAdapter -Connected:$false -Confirm:$false


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Hello LucD,

Thanks for helping me.

NICs are not disconnecting. The script just ran and doing nothing. Not seeing any tasks in vCenter.

pastedImage_1.png

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check if any VMs are selected?

Are VMware Tools installed?

What does this return

Get-VM -Name (Get-Content -Path D:\VMware\vms.txt) |

where{$_.Guest.OSFullName -match "Windows 10"}


And this?

Get-VM -Name (Get-Content -Path D:\VMware\vms.txt) |

where{$_.Guest.OSFullName -match "Windows 10"} |

Get-NetworkAdapter


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Hi,

I guess I am getting something. If I use this command "where{$_.Guest.OSFullName -match "Windows 10"}" then I am not getting the VMs info. But if I # it then the NICs are disconnecting. But the script is working only for the powered on VMs. Is there anyway we can get it worked for power on/off VMs ?

pastedImage_0.png

pastedImage_1.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That the VMs do not get through the Where-clause could be because the VMware Tools are not installed or not running.

Are the VMware Tools installed?

When a VM is powered off, you obviously can't connect/disconnect it from the network.

But you can use the StartConnected switch instead of the Connected switch.

In that case, the network will not be connected the next time the VM is powered on.


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

0 Kudos
NeenaJim
Enthusiast
Enthusiast
Jump to solution

Hello LucD

These are test VMs. I didnt check the script on Prod VMs. Hence these test VMs doesnt have VMware tools installed in it.

But your suggestion worked.

Thank you again Smiley Happy

0 Kudos