In this post I will explain how to run a PowerCLI command to connect or disconnect all virtual machine network adapters. Recently I experienced a power failure in one of my data centres that took out one of my SANs as well a host that held my vCenter server. When the kit was powered back on and vCentre was responding, an odd occurrence took place where all virtual machines managed by this vCenter server had the “Connect On Power On” check box enabled but the “Connected” check box wasn’t. At the time the only way to rectify this issue was to manually go though each virtual machine and check the box for the adapter to be connected. Not a fun experience.
To avoid the requirement for manual intervention to solve this issue for each virtual machine in the future, I have put together a PowerCLI command that will run though all virtual machines and connected their respective network adapters.
To do so, first load PowerCLI and connect to your vCenter server with the following command:
Connect-VIServer -Server vcenter.domain.local -User domain/username -
Following this, run the below command. This will run through all virtual machines managed by vCentre and connect network adapters 1 and 2. You can add additional adapters to be connected by simply adding more into the command e.g. “Network adapter 3″,”Network adapter 4″ etc.
Get-VM | Get-NetworkAdapter -Name “Network adapter 1″,”Network adapter 2″ | Set-NetworkAdapter -Connected:$true -Confirm:$false
I hope you found this post useful, and remember to look out for my future posts on PowerCLI.