Scenario 23

< Back | Next>

Scenario:

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.

Requirements:

Environment Information:

Objective: : 8.1 Execute VMware Cmdlets and Customize Scripts Using PowerCLI

Guide Reference(s):

 

Click Here For Solution

 

Solution

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 }