Alan's Blog

"Yeah. I wrote a script that will do that."

Menu
  • About My Blog
Menu

PowerShell:Start RDP After Reboot

Posted on March 3, 2013February 4, 2023 by Alan

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:

Set-ExecutionPolicy unrestricted
									

Revision note 3/4/2012:  I have updated the script to make the MsgBox SystemModal — which is required for it to have focus.

Leave a Reply

You must be logged in to post a comment.

Search

Please Note

All the scripts are saved as .txt files. Newer files have a “View Script” button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use “Save Target As”. Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with version 3 or later.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient.  If you find a post error or a script which doesn’t work as expected, I appreciate being notified.  My email is my first name at the domain name, and you are welcome to contact me that way.

Tags

1E ACLS Active Directory ActiveDirectory ADSI Advanced Functions Audit Change Administrator Password COMObject Computer Groups DateTime Desktop DNS Excel FileScriptingObject Forms General GPO GPS Group Policy Hacks ISE Lockout logons NAV740 Nessus OU OU permissions Outlook Pick Folder Power PowerShell Powershell Scriptlets RDP SCCM schedule reboot Scripting Security Shell.Application user information VBA Windows Update WMI WordPress WPF

Categories

akaplan.com

  • Back to Home Page

Archives

Scripting Sites

  • A Big Pile of Small Things
  • Adam, the Automator
  • Art of the DBA
  • Ashley McGlone
  • Boe Prox
  • Carlo Mancini
  • DexterPOSH
  • Doug Finke
  • Jaap Brasser's Blog
  • JeffOps The Scripting Dutchman
  • Jonathan Medd's Blog
  • Keith Hill's Blog
  • LazyWinAdmin
  • Nana Lakshmanan
  • PowerShell Magazine
  • PowerShell Team Blog
  • PowerShell.org
  • PwrShell.net
  • Richard Siddaway's Blog
  • Ryan Yates' Blog
  • Skatterbrainz
  • The Lonely Administrator

SQL Site

  • Art of the DBA

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Alan's Blog | Theme by SuperbThemes

Terms and Conditions - Privacy Policy