Thursday, January 17, 2013

Quick and Dirty Powershell

I didn't want to use psexec and when I tried to use it, I failed my first attempt.

Non-Destructive test to make sure I have the correct syntax:

Get-Content .\SMSReportResults.csv | ForEach-Object {If (test-connection $_ -Count 1 -quiet) {get-childitem \\$_\c$\windows\system32\grouppolicy\machine\registry.pol}}
Destructive command that will delete the registry.pol file which will be recreated next time SCCM checks for updates
Get-Content .\SMSReportResults.csv | ForEach-Object {If (test-connection $_ -Count 1 -quiet) {remove-item \\$_\c$\windows\system32\grouppolicy\machine\registry.pol}}

Quick explanation on what every step does:

  • Get-Content: Reads the lines from file as an array
  • ForEach-Object: Takes the array and does {}
  • If (test-connection $_ -Count 1 -quiet): Quick ping test (1 ping) to see if device is online returns true if online
  • get-childitem: is equivalent to dir or ls
  • remove-item is equivalent to del or rm
Curious to see if there is a way to create a wrapper powershell script that will allow someone used to psexec to use the same context for powershell equivalents.

No comments:

Post a Comment