Tuesday, September 6, 2011

Zero Day - A Novel by Mark Russinovich

Just finished reading this book and have to say that if you are into hacker type computer novels with good story lines then you must read this book. There are plenty of reviews on Amazon so I wont go into too much detail but can say that this is right up there as one of my favourite books. General plot is terrorists trying for world domination / destruction by creating computer malware. Lots of techie goodness for those of us so inclined but not so much that it ruins the story or makes it unreadable for those of you less so. The author, Mark Russinovich is a top tech at Microsoft and comes from sysinternals fame (think procmon etc). He writes very well and this is a great effort for his first novel. If you have read other books like The Daemon and FreedomTM then you will definitely enjoy this. 2 thumbs up.

Friday, January 14, 2011

Powershell script to ping multiple machines

 

Here is a script that I wrote for work that allows me to ping all of my servers with one command from Powershell. Note that you need Powershell Version 2 installed and the script is designed to take its list of servers to ping from 3 text files that are saved in a folder called PingServers which is located on the desktop (PDCServers.txt, BDCServers.txt and RemoteSites.txt). Just put the server netbios name in the text file and the script will do the rest.

Its all pretty basic and you will probably need to alter it a bit to suit your environment but it is very useful and saves me a bit of time in doing my morning checks.

It will write in green text if a server appears to be up. It will write in red text if the server appears to be down. At the end it will give you a count of how many servers did not respond.

Simply copy the below and save it in a file called PingServers.ps1. Then to run it open up powershell, browse to the directory where you saved the script and then type ./PingServers.ps1.

 

 

Clear

$errorcount = 0

Write-Host "`n" "Pinging PDC Servers..." "`n" -Fore "White"

$PingMachines = Gc "h:\desktop\PingServers\PDCServers.txt"

ForEach($MachineName In $PingMachines)

    {
    $PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
    Select-Object StatusCode
    If ($PingStatus.StatusCode -eq 0)
        {Write-Host $MachineName "appears to be up " -Fore "Green"}
    Else
        {Write-Host $MachineName "is not responding to ping requests" -Fore "Red"
        $errorcount = $errorcount + 1
        }       
    }

Write-Host "`n" "Pinging BDC Servers..." "`n" -Fore "White"

$PingMachines = Gc "h:\desktop\PingServers\BDCServers.txt"

ForEach($MachineName In $PingMachines)
    {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
    Select-Object StatusCode
    If ($PingStatus.StatusCode -eq 0)
        {Write-Host $MachineName "appears to be up " -Fore "Green"}
    Else
        {Write-Host $MachineName "is not responding to ping requests" -Fore "Red"
        $errorcount = $errorcount + 1
        }
    }


Write-Host "`n" "Pinging Remote Sites Wlgtn and ChCh Servers..." "`n" -Fore "White"

$PingMachines = Gc "h:\desktop\PingServers\RemoteSites.txt"

ForEach($MachineName In $PingMachines)
    {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
    Select-Object StatusCode
    If ($PingStatus.StatusCode -eq 0)
        {Write-Host $MachineName "appears to be up " -Fore "Green"}
    Else
        {Write-Host $MachineName "is not responding to ping requests" -Fore "Red"
        $errorcount = $errorcount + 1
    }
}

   
if ($errorcount -gt 0)
{
Write-Host ("`n Number of errors detected is $errorcount") -Fore "Red" "`n"
}