VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Adding a wait time to a script

Hello,

I am brand new to scripting and I am working towards being able to deploy a large number of VMs from a .csv file and then customize their network settings once deployed.  I know that there are probably scripts already on the Internet that will accomplish this, but I'm trying to learn so I would like to build the script from scratch so that I full understand it.  Here's what I have so far:

Connect-VIServer -Server MYVCSERVER.MYDOMAIN.local -User MYDOMAIN\USERNAME -Password MYPASSWORD

New-vm -vmhost prodh1.MYDOMAIN.local -Name TEST-SVR02 -Template W2K8R2SP1 -Datastore IOMEGA -OSCustomizationspec W2K8R2SP1 -Location _Tobedeleted| Start-VM

get-vm "TEST-SVR02" | Get-VMGuestNetworkInterface -Guestuser Administrator -GuestPassword "MYPASSWORD" |?{$_.name -eq "Local Area Connection 3"} | set-vmguestnetworkinterface -Guestuser Administrator -GuestPassword "MYPASSWORD" -IPPolicy static -IP 192.168.1.25 -Netmask 255.255.255.0 -Gateway 192.168.1.1 -DNS 192.168.1.2,192.168.1.3

Get-NetworkAdapter "TEST-SVR02" | Set-NetworkAdapter -NetworkName VM1 -Confirm:$false

Each line in the code is working, however, the VM that is created must be deployed, then customized, only then can the network settings be changed since the VMtools needs to be running in order to customize the network settings.  The total time for this to complete is about 20 minutes.

Is there a simple way to either:

1.   have the script wait for the OS customization to complete before attempting to change the network settings

or

2.  have the script wait about 20 minutes to allow for the deployment/customization to complete

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Have a look at the post from Vitali called Waiting for OS customization to complete


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at the post from Vitali called Waiting for OS customization to complete


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

0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

WOW, that link contains both an incredibly simple and incredibly complicated answer, both look awesome.  I'm going to start with adding a sleep timeout to my script, then move onto the more complicated one which waits for OScustomization to complete successfully.

Many thanks!

0 Kudos