-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUptime.ps1
More file actions
69 lines (49 loc) · 2.55 KB
/
Uptime.ps1
File metadata and controls
69 lines (49 loc) · 2.55 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
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Gets COMPUTER UP Time server STATUS !!! FUN STUFF
.EXAMPLE
'one', 'two', 'three' UPTime.ps1
.EXAMPLE
UPTime.ps1 -computername localhost
.EXAMPLE
UPTime.ps1 -computername one, two, three
.EXAMPLE
get-content <ServerList.txt> or <ServerList.csv> | Netwmi.ps1
.PARAMETER computername
one or more computername, or IP address... peace to America!
#>
Param(
[Parameter (Mandatory=$true,ValuefromPipeline=$true)]
[string[]] $computername,
[string] $errorlogpath = 'c:\temp\server_Uptime_errors.log'
)begin{
$host.UI.RawUI.WindowTitle = "UP Time"
}
process{
foreach ($computer in $computername) {
Write-Verbose "about to query $computer"
try {
$serverislive =$true
$who = Get-WMIObject Win32_ComputerSystem -computername $computer | Select-Object -ExpandProperty name
$EndTime = get-date
$StartTime = gwmi win32_operatingsystem -computername $computer | %{ $_.ConvertToDateTime($_.LastBootUpTime) }
$Server_uptime = New-TimeSpan -Start $StartTime -End $EndTime
} catch {
$serverislive = $false
Write-Verbose "$computer failed wrting to $errorlogpath "
Write-Verbose " Error was $MyErr"
$computer | Out-File $errorlogpath -append
}
$props = @{ 'Number of Hours '= $Server_uptime.Minutes ;
'Number of Minutes '=$Server_uptime.Hours ;
'Number of Days ' = $Server_uptime.Days ; }
#'server computername' = $who ;
#'server name you entered ' = $computer ;}
$obj = New-Object -TypeName PSObject -Property $props
$allthing = $Server_uptime | select Days, Hours, Minutes | Format-Table -AutoSize
$allthing1 = $who , $allthing
Write-Host " "
Write-Output $allthing1
}
}
end{}