# 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
}