Due to the innumerable reboots that operating systems like Windows 2012 R2 undergo, it can be difficult to know exactly when the deployment process has completed. One illustration of post-scripting with Guest Customization is using the Microsoft “msg” command to send messages to management terminal indicating that the process has completed. This involves creating a small batch or .cmd file within the template to send the message, and an call out in the Guest Customization Spec for the associated VM. The Msg command assumes the session being receiving is in RDP, and in Windows 7/8 you may well need to adjust the registry to allow the communication to flow. By using regedit to navigate to: HKLM\ SYSTEM\ CurrentControlSet\ Control\ Terminal Server\, and then change the following value to AllowRemoteRPC by 1.

In this case the script called SendMessageToMike.cmd created. The first line creates a simple “message.txt” file which includes Microsoft environment variables to ensure the hostname and domain name is correctly reported. The second line sends a message to the management PC called “mikelaverick-pc” using the contents of the message.txt. Finally, the temporary “message.txt” file is deleted the locally logged on administrator is logged out.

echo The VM called %computername% has completed the Sysprep process. It is now ready for use > c:\message.txt msg
administrator /server:mikelaverick-pc < c:\message.txt 
del c:\message.txt 
logoff 

On the properties of the Guest Customization, Administrator AutoLogon is enabled, and the RunOnce options are configured to run the script. It’s important to note that this autologon is to the local administrator, not to the domain – and it takes place after the VM joined the domain. Any scripting that requires domain rights will need to take this into account.

Screen Shot 2014-05-12 at 18.14.34.png

Screen Shot 2014-05-12 at 18.14.46.png

Once the VM has joined the domain, the auto-login process should occur, and the script will execute producing this message on the destination management system.

Screen Shot 2014-05-13 at 10.58.32.png