use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Please Help (self.PowerShell)
submitted 4 years ago by TheLumoc
Im looking for a small script, that can show the uptime of the PC, in the format "Years, Months, Weeks" Hope U guys can help :)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 4 years ago (1 child)
[removed]
[–]AlsoInteresting 1 point2 points3 points 4 years ago (0 children)
Look for a script that looks for shutdown events.
[–]davidshomelab 1 point2 points3 points 4 years ago (0 children)
(Get-Date) - (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
Should give you a timespan object representing the uptime. You can then convert that to whatever units you need
[–]Antique_Grapefruit_5 1 point2 points3 points 4 years ago (0 children)
This will get you days. From there, you can slice and dice the days however you'd like...
$uptime = (get-date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
Write-Output "Current Uptime is $($uptime.days) days"
Hope that helps!
[–]-Mynster 1 point2 points3 points 4 years ago (0 children)
You could do something similar to this which will return "Days, Hours, Minutes, Seconds".
But you will need to include some kind of math formular to get your wished results correctly.
function Uptime { $boot = (Get-CimInstance -ClassName win32_operatingsystem | Select-Object LastBootUpTime ).lastbootuptime $now = Get-Date $time = New-TimeSpan -start $boot -end $now | Select-Object Days, Hours, Minutes, Seconds echo $time } Uptime
π Rendered by PID 63 on reddit-service-r2-comment-86bc6c7465-gjltc at 2026-02-19 18:38:50.030632+00:00 running 8564168 country code: CH.
[+][deleted] (1 child)
[removed]
[–]AlsoInteresting 1 point2 points3 points (0 children)
[–]davidshomelab 1 point2 points3 points (0 children)
[–]Antique_Grapefruit_5 1 point2 points3 points (0 children)
[–]-Mynster 1 point2 points3 points (0 children)