Archive for the ‘Powershell’ Category

Posted by keith.wirch at October 16, 2013

Category: Powershell, Uncategorized

I find VBScript to be buggy and doesn’t flow very well for me.  I’m still decent at it but Powershell has been my scripting language of choice for a while.  Here is another little diddy I made out of Powershell.

I present to you…. File Delete!  Yea it’s a common thing you do I know but darn it, I don’t like using the admin share all the time to delete files off hundreds of computers.  I execute this script… kick back… watch the beauty of the text scroll up my screen and watch for any errors and investigate.  All while the user is using the computer and they never know!  Makes me feel like some sort of wizard… or ninja….

Ok, grown up time Keith.

So the script is similar to the rest.  Change the last line to your computers.txt file path.

Line 4 is then the file path you want to delete on your remote computer.  This script takes advantages of UNC paths for windows so when you enter this part in, just think of it as you would for a standard admin share.  Remember you will need access to the file location.  Powershell will use the credentials that was opened with your Powershell or Powershell ISE window.

Because I am also experimenting with using Log files, you’ll also need to make an area for the log file for this script.  Or you can delete that area.  I’m starting to like log file though in my scripts.

 function delete-remotefile {
           $file = "\\$_\c$\path\deleted\folder\or\items"
           if (test-path $file)
           echo "$_ File Exists"
           Remove-Item $file -force
           echo "$_ Files deleted"

 # Reads list and pipes to function
 Get-Content C:\Scripts\FileDelete\Computers.txt | delete-remotefile >> C:\Scripts\FileDelete\Log.txt

Posted by keith.wirch at October 15, 2013

Category: Powershell

Small one but a good one.  This script will ping all hosts in a text file to see if they are up.  It’s great in the of case you want to see all of the stations in a classroom before you push an update or something.

Here it is.

$names = Get-Content "C:\Scripts\Computers.txt"

foreach ($name in $names) {

if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue ) {

Write-Host "$name is up" -ForegroundColor Magenta


else {

Write-Host "$name is down" -ForegroundColor Red



Line 1 is where you designate your text file of computers.  From there you just execute the powershell script and it will run something like the output below.  I’d reccomend making a bunch of “computer” files for each room you will routinly check like this and then only changeing line 1 to match what you need.

Again, some areas are blurred to protect the innocent!  MSPaint for the win my friends!