I’m going through a scenario where i boot a Newly built VM with a sysprepped vhd attached, once the setup process completes with installing devices etc and the OS gets loaded i wanted to wait till this entire process finishes and the VM is assigned an IP address via DHCP.
PS C:\Users\Administrator> Start-VM -Name dv.VMWIN2K8R2-3.Hng
PS C:\Users\Administrator> while ((Get-VM -Name dv.VMWIN2K8R2-3.Hng | select -ExpandProperty networkadapters).ipaddress[0] -match $null)
{
Start-Sleep 3
Write-Host "Waiting to Acquire IP Address" -ForegroundColor green
}
$ipaddress=(Get-VM -Name dv.VMWIN2K8R2-2.Hng | select -ExpandProperty networkadapters).ipaddresses[0]
Write-Host "VM has acquired an IPAddress of $ipaddress"
I Tried the above snippet but the while loop never run’s, i have noticed that while VM is shutdown the ip address parameter is blank so i thought to match it till it shows Null and when i boot up the VM and once the server gets an IP address by DHCP it should exit the while loop and print the IP address on console.
Hi Guys i was able to solve the issue, i used the Get-VMNetworkAdapter Cmdlet and it solved the issue