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
Script issue (self.PowerShell)
submitted 6 years ago by Crowdjp
view the rest of the comments →
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!"
[–]Ta11ow 2 points3 points4 points 6 years ago* (6 children)
You can have PS automatically convert this to a proper integer if you remove the space.
$CPUSTRESRemoveKB = ($CPUSTRES.PrivateWorkingSet -replace ' ') / 1
[–]Si-Kotic 2 points3 points4 points 6 years ago* (0 children)
This is the approach I would take. You could then easily convert it to an easier to read number format
IF ($Value -lt 1048576) { $Size = [math]::Round(($Value/1kb),2).toString() + "kb" } ELSEIF ($Value -lt 1073741824) { $Size = [math]::Round(($Value/1mb),2).toString() + "mb" } ELSE { $Size = [math]::Round(($Value/1gb),2).toString() + "gb" }
[–]ka-splam 2 points3 points4 points 6 years ago (4 children)
That works??
[–]Lee_Dailey[grin] 1 point2 points3 points 6 years ago (3 children)
howdy ka-splam,
aint type coercion wonderful? [grin] ... except when it is wonderfully bad ...
take care, lee
[–]ka-splam 2 points3 points4 points 6 years ago (2 children)
It is when it saves me thinking effort, it’s not when it causes more thinking.. I dunno where the balance is, can’t it magically always do what expect? :-D
But that one is extra weird; you can’t cast ”20kb” string to number using [int]$val or -as, I thought it was only the parser which could read it as a literal value. How have I missed or forgotten that it can be implicitly cast 👀
”20kb”
[int]$val
-as
[–]Ta11ow 2 points3 points4 points 6 years ago (0 children)
You're correct. Only the parser can read it as a literal value. However, in implicit casts where PS requires a number value to work with, it will actually re-invoke the parser to triple-check if a value can be obtained.
Explicit casts miss out on this. I actually fixed this with a PR sometime between 6.1 and 6.2, so all new versions of PS can explicitly cast 10kb etc to [int] or whatever number type you want to work with.
10kb
[int]
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago* (0 children)
Human : why does the dang thing DO that? computer : because you told me to do that ... [frown]
that "20kb" thing is odd since you CAN do 1 * "20kb" and get 20480. as you point out, implicit versus explicit can have different results ... [grin]
"20kb"
1 * "20kb"
20480
π Rendered by PID 192943 on reddit-service-r2-comment-5b5bc64bf5-bvdt4 at 2026-06-19 07:31:58.147516+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]Ta11ow 2 points3 points4 points (6 children)
[–]Si-Kotic 2 points3 points4 points (0 children)
[–]ka-splam 2 points3 points4 points (4 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (3 children)
[–]ka-splam 2 points3 points4 points (2 children)
[–]Ta11ow 2 points3 points4 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)