I'm relatively new to Powershell and PowerCLI (as in 1 week ago relatively new) and I'm trying to stumble through the process of provisioning about 12 VM's on a recurring basis for a class. I can deploy VM's from a template just fine, however I want to assign specific IP addresses to VM's once they're done sysprep'ing. I am using Powershell 1.0 and PowerCLI 4.0.1 in a windows 2003 VM (also vcenter on that box). The VM's that I'm deploying are also Windows 2003 and sysprep just fine. Here is the section in my script that I'm using to set the IP address:
$net1 = "LAN"
set-vmguestnetworkinterface -VmGuestNetworkInterface $net1 -vm P2V_student06 -hostuser root -hostpass ****** -guestuser administrator -guestpass ****** -ippolicy static -gateway 192.168.20.1 -netmask 255.255.255.0 -ip 192.168.20.126
Here is the output of get-vmguestnetworkinterface for that VM:
VMId : VirtualMachine-vm-578
SubnetMask : 255.255.255.0
NicId : VirtualMachine-vm-578/4000
Name : LAN
IPPolicy : Dhcp
Ip : 192.168.20.188
Dns : {192.168.20.2}
DefaultGateway : 192.168.20.1
Description : Intel(R) PRO/1000 MT Network Connection
Mac : 00-50-56-B7-36-45
RouteInterfaceId :
DnsPolicy : Dhcp
WinsPolicy : Dhcp
Wins :
When I run the script- it gives the following output:
Name Port User
-
-
-
192.168.20.35 443 Administrator
Set-VMGuestNetworkInterface : Cannot bind parameter 'VmGuestNetworkInterface'. Cannot convert value "LAN" to type "VMware.VimAutomation.Types.VMGuestNetworkInterface". Error: "Invalid cast from 'System.String' to 'VMware.VimAutomation.Types.VMGuestNetworkInterface'."
At C:\powercli_scripts\test_setup_vsphere_4.0_class.ps1:6 char:53
+ set-vmguestnetworkinterface -VmGuestNetworkInterface <<<< LAN -vm P2V_student06 -hostuser root -hostpass ****** -guestuser administrator -guestpass ****** -ippolicy static -gateway 192.168.20.1 -netmask 255.255.255.0 -ip 192.168.20.126
Originally the VM had the standard "Local Area Connection" for the network adapter name. I thought it might be having problems with spaces so I renamed it to "LAN" and it still errors out. Can anyone think of what I'm doing wrong? This almost seems like a bug of some kind.
Thanks in advance for any help you can offer. I'm pulling my hair out being so close to getting this to work it's driving me NUTS!
Best Regards,
Eric Steed