Thursday, December 18, 2008

Powershell Example

What Can I Do With Windows PowerShell?

Scenario: Needed to test disaster recovery procedures at the hospital.  All employees were told to go to a website and type in a url.

Problem: Workstations located in the doctor-patient procedure rooms don't have that ability because of patients have been known to 'surf' the web while waiting to be helped.

Solution: Needed to copy a new http:// shortcut to every workstation ASAP

Tools used: Active Directory Users and Computers and Powershell

1. Export a list of all Procedure Workstations from Active Directory
2. I was going to use psexec tool but then remembered powershell was capable of running a foreach loop
3. Started with: cat 'secured workstations.txt' | foreach-object -process {echo copy-item 'shortcut.lnk' \\$_\c$\documents and settings\userprofile\start menu}
4. After failure I started looking at backslash as an escape character and putting parts of the phrase in quotes
5. Tested one computer with: echo 'computername' | foreach-object -process {copy-item 'shortcut.lnk' \\$_"\c$\documents and settings\userprofile\start menu\"}
6. Ran final command: cat 'secured workstations.txt' | foreach-object -process {copy-item 'shortcut.lnk' \\$_"\c$\documents and settings\userprofile\start menu\"}

No comments:

Post a Comment