PoshCode Logo PowerShell Code Repository

Difference between
modified post 6837 by Rallo on Tue 11th Apr 18:46 and
original post 3861 by Ton Siemons on Fri 4th Jan 03:04
Showold version | new version | both versions

    
11
$snapins = "vmware.vimautomation.core"
22
foreach ($snapin in $snapins){if (!(Get-PSSnapin $snapin -ErrorAction SilentlyContinue)){Add-PSSnapin $snapin}}
44
$vserver = "vmware vCenter Server"
55
$vNetwork = "General_Services"
66
$logfile = "d:\Scripts\log\vm.log"
77
$subnet = "255.255.255.128"
99
connect-viserver -Server $vserver
1010
$vms = Get-VM
1111
foreach ($vm in $vms){
1212
	$nw = $vm|Get-NetworkAdapter
1313
	if (($nw.networkname) -like $vNetwork){
1414
1515
		Foreach($NIC in $NICs) {
1616
			try{
1717
				$NIC.EnableStatic($nic.ipaddress, $subnet)
1818
				$string = "$vm is adapted"
1919
				$string
2020
				$string|Out-File -FilePath $logfile -Append -Encoding OEM
2121
			}
2222
			Catch{
2323
				$string = "$vm is not adapted"
2424
				$string
2525
				$string|Out-File -FilePath $logfile -Append -Encoding OEM
2626
			}
2727
		}
2828
	}
2929
}

ContributeMost Recent Contributions (feed)

Contribute ... Next Page