Depuis combien de temps est démarré un serveur.

Connaitre depuis combien de temps un serveur est démarré.
Ce script permet de savoir quand a eu lieu le dernier reboot d’un serveur.

$srv = Read-Host "Please enter the server"
$os = Get-WmiObject Win32_OperatingSystem -ComputerName $srv
$uptime = $os.LastBootUpTime
$year = $uptime.substring(0,4)
$Month = $uptime.Substring(4,2)
$Day = $uptime.Substring(6,2)
$hour = $uptime.Substring(8,2)
$min = $uptime.Substring(10,2)
$sec = $uptime.Substring(12,2)
$RebootTime = new-Object System.DateTime($year,$month,$day,$hour,$min,$sec)
$now = [System.DateTime]::Now
$uptime = $now.Subtract($RebootTime)
Write-Host "$srv" -NoNewLine
Write-Host " ==> Uptime: " -NoNewLine
Write-Host "$($uptime.days)" -NoNewLine -ForeGroundColor Red
Write-Host " days, " -NoNewLine
Write-Host "$($uptime.Hours)" -NoNewLine -ForeGroundColor Red
Write-Host " hours, " -NoNewLine
Write-Host "$($uptime.Minutes)" -NoNewLine -ForeGroundColor Red
Write-Host " minutes, " -NoNewLine
Write-Host "$($uptime.seconds)" -NoNewLine -ForeGroundColor Red
Write-Host " seconds, "

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *