diff --git a/Automation/src/SystemUptime/README.md b/Automation/src/SystemUptime/README.md new file mode 100644 index 00000000..188fb7d4 --- /dev/null +++ b/Automation/src/SystemUptime/README.md @@ -0,0 +1,2 @@ +# Windows bases systems uptime +This should list 2 results to recieve an accurate time estimation diff --git a/Automation/src/SystemUptime/SystemUptime.ps1 b/Automation/src/SystemUptime/SystemUptime.ps1 new file mode 100644 index 00000000..bd3127e5 --- /dev/null +++ b/Automation/src/SystemUptime/SystemUptime.ps1 @@ -0,0 +1,28 @@ +### Check Server Start Up Date ### +### Server UpTime ### + +##Method 1 +systeminfo.exe | find "System Boot Time" + +Write-Host -ForegroundColor green "WIM Uptime" + +##Method 2 +function GetUptime { + Param ($server) + Try { + $win32_os = Get-WmiObject Win32_OperatingSystem -ComputerName $server -ErrorAction Stop +   + # Convert to date times + $local = $win32_os.ConvertToDateTime($win32_os.LocalDateTime) + $boot = $win32_os.ConvertToDateTime($win32_os.LastBootUpTime) +   + # Calculate the uptime and return it + $uptime = ($local - $boot) + } + Catch { + $uptime = "" | Select-Object Days + $uptime.Days = "$error[0].exception.message" + } + Finally { $uptime } +} +GetUptime localhost