6
Found a script and need help changing it's output a little
Post Flair (click to view more posts with a particular flair)
Post Body
So I found a script that polls AD, finds all computers matching a string and then outputs it's uptime and free drive space. I'd like to make the uptime report a little more easily readable and need some help. Currently this is what it looks like
uptime computer
09:49:06.7148030 Computer1
18:06:40.9940440 Computer2
18:06:41.1188480 Computer3
18:06:41.1656495 Computer4
What I'd like to see is something more like this
uptime computer
0 Days 9 Hours 45 Minutes Computer1
0 Days 18 Hours 6 Minutes Computer2
Here's the script snippit:
Function Get-UpTime
{ Param ([string[]]$servers)
Foreach ($s in $servers)
{
if(Test-Connection -cn $s -Quiet -BufferSize 16 -Count 1)
{
$os = Get-WmiObject -class win32_OperatingSystem -cn $s
New-Object psobject -Property @{computer=$s;
uptime = (get-date) - $os.converttodatetime($os.lastbootuptime)} }
ELSE
{ New-Object psobject -Property @{computer=$s; uptime = "DOWN"} }
}
}
#end function Get-Uptime
For those interested in the script, It's here Make sure to change the line under the line that says "Entry Point" that reads
[array]$servers = ([adsisearcher]"(&(objectcategory=computer)(OperatingSystem=*server*))").findall() |
foreach-object {([adsi]$_.path).cn}
And change where it says "OperatingSystem=server" to read "OperatingSystem=7"
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
Yes
Total Karma
66,614
Link Karma
30,920
Comment Karma
35,639
Profile updated: 6 days ago
Posts updated: 9 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 9 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PowerShell/...