You are the administrator of a large vSphere environment where management automation is extremely important. You need to produce PowerCLI to implement various changes to large sets of VMs. You need to create a PowerCLI script that can be used to change the connection state for all network adapters for all VMs.
Chapter 1 – PowerCLI - Usage
Connect-VIServer vcenter-01
$MyNetAdapters = get-vm | Get-NetworkAdapter
foreach ($NIC in $$MyNetAdapters) { $NIC.ConnectionState }
foreach ($NIC in $$MyNetAdapters)
{ if ($NIC.ConnectionState.Connected)
{Set-NetworkAdapter $NIC -Connected:$false -Confirm:$false}
else
{Set-NetworkAdapter $NIC -Connected:$true -Confirm:$false}
}
$MyNetAdapters = get-vm | Get-NetworkAdapter
foreach ($NIC in $$MyNetAdapters) { $NIC.ConnectionState }