VMware Cloud Community
MikeBrosas
Contributor
Contributor

Create Multiple VMs and assign Static IP Addresses = 'Get-VMGuestNetworkInterface' error

Please help, Im creating VMs and assign Static IP to each VM, I use below scripts, but when I am in 'Get-VMGuestNetworkInterface' to customize network, I recieved below error:

SCRIPT:

$esxName = "XXXXXX"

$template = "Win7"

$datastore = "XXXXXX"

$newVmList = @(

@{"Name" = "Test01"; "IP" = "192.168.1.101"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM Network"; },

@{"Name" = "Test02"; "IP" = "192.168.1.102"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM Network"; },

@{"Name" = "Test03"; "IP" = "192.168.1.103"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM Network"; }

)

$taskTab = @{}

Connect-VIServer -Server XXXXXX -User administrator@XXXXXX.com -Password XXXXXX

# Create all the VMs specified in $newVmList

foreach($VM in $newVmList) {

     $taskTab[(New-VM -Name $VM.Name -VMHost (Get-VMHost -Name $esxName) -Template $template -Datastore $datastore -RunAsync).Id]=$VM.Name

}

# Start each VM that is completed

$runningTasks = $taskTab.Count

while($runningTasks -gt 0){

Get-Task | % {

  if($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success"){

   Get-VM $taskTab[$_.Id] | Start-VM

   $taskTab.Remove($_.Id)

   $runningTasks--

  }

  elseif($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error"){

   $taskTab.Remove($_.Id)

   $runningTasks--

  }

}

Start-Sleep -Seconds 15

}

# START HERE 

# Wait for OS Customization 

Start-Sleep -Seconds 90

# Customize network

foreach($VM in $newVmList) { 

    Get-NetworkAdapter -VM $VM.Name | Set-NetworkAdapter -NetworkName $VM.NetworkName -Confirm:$false 

    Get-VM -Name $VM.Name | Get-VMGuestNetworkInterface -Guestuser "user" -GuestPassword "password" | ? { $_.name -eq "Local Area Connection" } | Set-VMGuestNetworkInterface -Guestuser "user" -GuestPassword "password" -IPPolicy static -IP $VM.IP -Netmask $VM.Netmask -Gateway $VM.Gateway -DNS $VM.DNS

}

ERROR:

Get-VMGuestNetworkInterface : The term 'Get-VMGuestNetworkInterface' is not recognized as the name of a cmdlet,

function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the

path is correct and try again.

At line:3 char:29

+     Get-VM -Name $VM.Name | Get-VMGuestNetworkInterface -Guestuser "u ...

+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Get-VMGuestNetworkInterface:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

0 Kudos
1 Reply
LucD
Leadership
Leadership

That cmdlet, and a few others, were removed in PowerCLI 10.0.0.

See New Release: VMware PowerCLI 10.0.0 under the section Deprecated Cmdlets and Property


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos