Z
Z
Z-RoVeR2018-06-14 11:17:24
PowerShell
Z-RoVeR, 2018-06-14 11:17:24

How to calculate the uptime of computers in a domain?

There is a need to collect the uptime of computers in the domain. Not all, but preferably from the list and import them into a file, preferably in exel. I already have a js script that can find out the uptime of a certain computer, but it has to enter the computer name before each check, which is tedious if there are more than 100 of them. Perhaps you can come up with something in PowerShell?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
blackbeard, 2018-06-14
@Z-RoVeR


$scriptBlock={
$wmi = Get-WmiObject -Class Win32_OperatingSystem
($wmi.ConvertToDateTime($wmi.LocalDateTime) – $wmi.ConvertToDateTime($wmi.LastBootUpTime)).TotalHours
}
$UpTime = @()
Import-Module ActiveDirectory
Get -ADComputer -Filter 'ObjectClass -eq "Computer"' -SearchBase "OU=someOu,DC=someDomain,DC=someTld" -SearchScope Subtree `
| % { $Uptime += `
(New-Object psobject -Property @{
"ComputerName" = $_.DNSHostName
"UpTimeHours" = (Invoke-Command -ComputerName $_.DNSHostName -ScriptBlock $scriptBlock)
}
)
}
$UpTime | Where-Object {$_.UpTimeHours -ne ""} | sort-object -property @{Expression="UpTimeHours"; Descending=$false} | `
Select-Object -Property ComputerName,@{Name="UpTimeHours"; Expression = {$_.UpTimeHours.ToString("#.##")}} | `
Format-Table -AutoSize

K
kkt, 2018-06-14
@kkt

create a list of computers
in a loop run through the list get wmi object then
do what you want

A
Andrey Ivanov, 2018-06-25
@rus0nix

If you do not want to use scripts, there is a softperfect network scanner program that can determine the Uptime of computers when scanning a network. Old versions of the program (<= 6) are free.

S
Sergey_abakan, 2018-08-08
@Sergey_abakan

You can use powershell module
https://m.habr.com/post/357974/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question