A lot of folks have been asking me why I haven’t written any PowerShell scripts. The answer is that I am pretty good at vbscript, and I couldn’t find anything that I wanted to do that I couldn’t do with vbscript.
Last week I spent some time waiting for a computer to reboot. I used ping -t to watch the replies, and then waited until I could use the Remote Desktop Connection (RDC) to connect using RDP. I thought to myself, “self — you sure have spent a lot of time waiting for systems to come up”. RDP2.ps1 is a PowerShell script that does the tedious watching for you. It will wait for both the system and the remote access interface to come up, and then will launch the RDC to the computer. You can run it interactively, or with the command line:
./rdp2.ps1 computername[:port] -WaitForReboot
The port is an option for nonstandard ports. -WaitForReboot does just that. If the system is still up when you launch the script, it will wait for it to reboot.
Like many first scripts, this is largely based on someone else’s work, see: http://poshtips.com/2013/02/12/check-rdp-availability-using-watch-rebootstatus-script/. I made a large number of changes in addition to launching the RDC. For those of you who have spent a lot of time with PowerShell, I am open to suggestions on how to make the code more elegant.
If you haven’t ever run a PowerShell script, you will find it is already installed on your Vista or later machine, and on Windows 2008/R2 servers. You must set the execution policy:
Revision note 3/4/2012: I have updated the script to make the MsgBox SystemModal — which is required for it to have focus.