The script below will tell me the uptime on PC's. I want to add the language that says if Uptime is greater than X amount of days then it will send a reboot in 15 Mins. Any help would be appreciated.
# This PS script provides Uptime and Pingstatus for list of computers. ####################################################################### $names = Get-Content "C:\Test\computers.txt" @( foreach ($name in $names) { if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue ) { $wmi = gwmi Win32_OperatingSystem -computer $name $LBTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime) [TimeSpan]$uptime = New-TimeSpan $LBTime $(get-date) Write-output "$name Uptime is $($uptime.days) Days" Write-Host "$name Uptime is $($uptime.days) Days" -ForegroundColor Green } else { Write-output "$name is not pinging" Write-Host "$name is not pinging" -ForegroundColor Red } } ) | Out-file -FilePath "C:\Test\results1.csv"
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
The script below will tell me the uptime on PC's. I want to add the language that says if Uptime is greater than X amount of days then it will send a reboot in 15 Mins. Any help would be appreciated.
# This PS script provides Uptime and Pingstatus for list of computers.
#######################################################################
$names = Get-Content "C:\Test\computers.txt"
@(
foreach ($name in $names)
{
if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue )
{
$wmi = gwmi Win32_OperatingSystem -computer $name
$LBTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime = New-TimeSpan $LBTime $(get-date)
Write-output "$name Uptime is $($uptime.days) Days"
Write-Host "$name Uptime is $($uptime.days) Days" -ForegroundColor Green
}
else {
Write-output "$name is not pinging"
Write-Host "$name is not pinging" -ForegroundColor Red
}
}
) | Out-file -FilePath "C:\Test\results1.csv"
Share this post
Link to post
Share on other sites