Check Uptime for Multiple Servers using Powershell - GUI based tool

Check Uptime for Multiple Servers using Powershell - GUI based tool

This tool will help you to determine the uptime for the multiple servers.

Script :


Function Get-Uptime{
Param([string]$server)
Begin {
function PingServer {
Param([string]$srv)
$pingresult = Get-WmiObject win32_pingstatus -f "address=’$srv’"
if($pingresult.statuscode -eq 0) {$true} else {$false}
}
function myUptime {
param([string]$srv)
$os = Get-WmiObject Win32_OperatingSystem -ComputerName $srv
$uptime = $os.LastBootUpTime
return $uptime
}
function ConvertDate {
param([string]$date,[string]$srv)
$year = $date.substring(0,4)
$Month = $date.Substring(4,2)
$day = $date.Substring(6,2)
$hour = $date.Substring(8,2)
$min = $date.Substring(10,2)
$sec = $date.Substring(12,2)
$RebootTime = new-Object System.DateTime($year,$month,$day,$hour,$min,$sec)
$now = [System.DateTime]::Now
$uptime = $now.Subtract($RebootTime)
$uptimeval = "$($uptime.days) days, $($uptime.Hours) hours, $($uptime.Minutes) minutes, $($uptime.seconds) seconds"
$lastReboot = $rebootTime.toString()
$sObject = new-Object -typename System.Object
$sObject | add-Member -memberType noteProperty -name ServerName -Value $srv
$sObject | add-Member -memberType noteProperty -name Days -Value $uptime.days
$sObject | add-Member -memberType noteProperty -name Hours -Value $uptime.Hours
$sObject | add-Member -memberType noteProperty -name Minutes -Value $uptime.Minutes
$sObject | add-Member -memberType noteProperty -name Seconds -Value $uptime.seconds
$sObject | add-Member -memberType noteProperty -name uptime -Value $uptimeval
$sObject | add-Member -memberType noteProperty -name LastReboot -Value $rebootTime.ToUniversalTime()
$sObject | add-Member -memberType noteProperty -name LastRebootUtc -Value $rebootTime.ToFileTimeUtc()
write-Output $sObject
}
Write-Host
$process = @()
$objCollection = @()
}
Process {
if($_){
if($_.ServerName ){
$process += $_.ServerName
}
else{
$process += $_
}
}
}
End {
if($Server){$process += $server}
$i = 1
foreach ($Server in $process){
write-progress $Server "Total Progress->" -percentcomplete ($i/$process.length*100)
if(PingServer $server){
$result = myUptime $server
$srvObject = ConvertDate $result $server
$objCollection += $srvObject
}
else {
Write-Host "Server [$server] not Pingable" -foregroundcolor red
}
$i = $i+1
}
Write-Output $objCollection
Write-Host
}
}


========================================================================

How to use:

1. Enter hostname in the text area. Note One hostname per line

2. There should be no white spaces while copy pasting the hostname in the textarea

3. Once done, click on Uptime Check

4. Depending on number of hostname entered output will take time to produce.

Output:

This is will generate two text file name Uptime.txt and BadPingResponse.txt, these text files will be saved at your desktop by default.

Screenshots:



Download :


Thanks you guys, Please comment if you have any query.
Have a Nice Day!



Previous
Next Post »
0 Comments