Monday, November 25, 2013

Simple Power Shell Script To Log Off Remote Desktop Users

Hi Friends,

As I've mentioned I'm running automation using Login VSI to test multiple VDI user logins and the problem is clean up.  Isn't clean up ALWAYS a nightmare!?  Well, I've pieced together a small Power Shell script that I've taken from 3 or 4 sources around the Net that I'd like to share with you.  Don't forget to save the file as a .ps1 for Power Shell.

So here's what it does. 

1.  You create a text file called servers.txt, or whatever you'd like and populate it with the names of the machines you want users logged off from.  If your machines are numbered sequentially and easy way to populate the file is using Excel.

2.  For the $cred variable you put in your domain and user who will be logging folks out.

3.  You kick off the script and a dialog box will pop up asking for your password.  This will be the only time it needs the password for that run.

So if you're cleaning up 4 or 40,000, this is a simple script to help you out.  I wish I could remember which sites I pieced the script together from, but I  can't remember.  So I'll send out a blanket thanks for all the sites that helped me!

Until Next Time!
-Brain


$cred = get-credential domain\user

foreach ($_ in get-content servers.txt)

{(gwmi win32_operatingsystem -credential $cred -ComputerName $_).Win32Shutdown(4)}

No comments:

Post a Comment