-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDevice_Uptime.ps1
More file actions
60 lines (56 loc) · 1.51 KB
/
Copy pathDevice_Uptime.ps1
File metadata and controls
60 lines (56 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Function Get_DeviceUpTime
{
param(
[Switch]$Show_Days,
[Switch]$Show_Uptime
)
$Last_reboot = Get-ciminstance Win32_OperatingSystem | Select -Exp LastBootUpTime
$Check_FastBoot = (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power" -ea silentlycontinue).HiberbootEnabled
If(($Check_FastBoot -eq $null) -or ($Check_FastBoot -eq 0))
{
$Boot_Event = Get-WinEvent -ProviderName 'Microsoft-Windows-Kernel-Boot'| where {$_.ID -eq 27 -and $_.message -like "*0x0*"}
If($Boot_Event -ne $null)
{
$Last_boot = $Boot_Event[0].TimeCreated
}
}
ElseIf($Check_FastBoot -eq 1)
{
$Boot_Event = Get-WinEvent -ProviderName 'Microsoft-Windows-Kernel-Boot'| where {$_.ID -eq 27 -and $_.message -like "*0x1*"}
If($Boot_Event -ne $null)
{
$Last_boot = $Boot_Event[0].TimeCreated
}
}
If($Last_boot -eq $null)
{
$Uptime = $Uptime = $Last_reboot
}
Else
{
If($Last_reboot -ge $Last_boot)
{
$Uptime = $Last_reboot
}
Else
{
$Uptime = $Last_boot
}
}
If($Show_Days)
{
$Current_Date = get-date
$Diff_boot_time = $Current_Date - $Uptime
$Boot_Uptime_Days = $Diff_boot_time.Days
$Real_Uptime = $Boot_Uptime_Days
}
ElseIf($Show_Uptime)
{
$Real_Uptime = $Uptime
}
ElseIf(($Show_Days -eq $False) -and ($Show_Uptime -eq $False))
{
$Real_Uptime = $Uptime
}
Return "$Real_Uptime"
}