Teeny Scripts that do Simple but Time Saving things.

Today, I made two tiny little scripts. I need to sort out error suppression - but these work great in a pinch, and can save a lot of time for what seem like simple tasks.

Ping test: There are a million of these, but this one works well enough for me, so there's that.

$serverlist = "C:\scripts\txt\list.txt"

foreach ($server in Get-Content $serverlist) {
    if (Test-Connection $server -errorAction SilentlyContinue) {
        Write-Host "$server is Online" -ForegroundColor Green
    } 
    else {
        Write-Host "$server is offline" -ForegroundColor Red
    }
} 

 

Check if a process is running on multiple servers: Yeah, this one happens more often than you think. And this little guy saved me a good half an hour or more just this evening.

#Check for Process
#JWS 2016

$servers = gc "C:\Scripts\txt\list.txt"

ForEach ($server in $servers) {

    if (get-process -ComputerName $server | where {$_.ProcessName -eq "processname"}) 
        { 
        Write-Host "processname is running on $server" -ForegroundColor Green
        }   
    else 
        {
        Write-Host "processname not found on $server" -ForegroundColor Red
        }

}

These little dudes took 5 minutes to throw together, and what a life saver. 

EDIT: Bonus Round! I combined them and took care of error suppression and made it even handier!

#Check for a Process on a server
#JWS 2016

$servers = gc "C:\Scripts\txt\list.txt"

ForEach ($server in $servers) {

    if (Test-Connection $server -Count 2 -ErrorAction SilentlyContinue) {

        if (get-process -ComputerName $server | where {$_.ProcessName -eq "processname"} -ErrorAction SilentlyContinue) 
            { 
            Write-Host "Process is Running on $server" -ForegroundColor Green
            }   
        else 
            {
            Write-Host "Process Not Found on $server" -ForegroundColor Red
            }
    }
    else  
    {
    Write-Host "$server is offline" -fore Red
    }

}