PoshCode Archive  Artifact [db5f1f50d2]

Artifact db5f1f50d2f7b85eb530a569f24933fd4258967b087f9cf492678543d7bab8fb:

  • File Re-IP-VMs.ps1 — part of check-in [1dcf731dc4] at 2018-06-10 12:56:48 on branch trunk — Re-IP VMware VMs based on the contents of a CSV (user: unknown size: 692)

# encoding: ascii
# api: powershell
# title: Re-IP VMs
# description: Re-IP VMware VMs based on the contents of a CSV
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 1284
# x-archived: 2009-08-25T01:00:32
#
#
foreach ($entry in (import-csv "spreadsheet.csv")) {
	$ipScript = @"
	`$NetworkConfig = Get-WmiObject -Class Win32_NetworkAdapterConfiguration
	`$NicAdapter = `$NetworkConfig | where {`$_.DHCPEnabled -eq "True"}
	`$NicAdapter.EnableStatic('$entry.IP','$entry.Netmask')
	`$NicAdapter.SetGateways('$entry.Gateway')
	"@

	Get-VM $entry.VMName | Invoke-VMScript -HostUser $entry.HU -HostPassword $entry.HP -GuestUser $gu -GuestPassword $gp $ipScript
}