Quick and dirty Powershell + Growl host watch

Needing a quick and dirty growl notification to know when a person restarted their computer, so I wrote up this originally one line script.

. '\libs\growl\Send-Growl 3.1.ps1';	#http://poshcode.org/1464
					#Might need to modify the file a little.

$str = @("down", "up");
$last_ds = $false;
while(1) {
	$new_ds = Test-Connection TargetHost -Quiet -Count 2;
	if($new_ds -ne $last_ds) {
		Send-Growl -Caption "Watchtower" -Message ("TargetHost is {0}" -f $str[$new_ds]);
	$last_ds = $new_ds;
	sleep 5;

Just copy and paste in ISE, modify and away you go!

Bonus points protip: Run in the background.

start-process powershell @("Hidden", "-File" "\path\to\above\script.ps1") -WindowStyle Hidden

Leave a Reply

Your email address will not be published. Required fields are marked *