Share via

PowerShell get-process result .WS (working set size) is Uint32 stored in Int32 (goes negative when large)

Anonymous
2015-05-13T22:20:54+00:00

I know this could be a problem in the WMI management structure definition for Process...

But as a process's working set grows larger, and crosses the 2048 MB boundary,

the returned number becomes negative, because it's incorrectly being treated as a

signed 32-bit integer, when it is actually an unsigned 32-bit integer.

(Note that this implies a maximum WS of 4096 *1K*1K minus 1.)

ps> (get-process firefox).WS.getType()

IsPublic IsSerial Name                                     BaseType

-------- -------- ----                                     --------

True     True     Int32                                    System.ValueType

ps> $x = (get-process firefox).WS

ps> $x.gettype()

IsPublic IsSerial Name                                     BaseType

-------- -------- ----                                     --------

True     True     Int32                                    System.ValueType

ps> $x

-2110365696

This would not be such a problem, except... Trying to cast as uint32 fails

ps> [uint32]$x

Cannot convert value "-2110365696" to type "System.UInt32". Error: "Value was either too large or too small for a

UInt32."

At line:1 char:1

  • [uint32]$x
  • 
    

    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvalidCastIConvertible

And converting it to int64 preserves the negativity

ps> [int64]$x

-2110365696

If I could set an int64's high longword to zero and low longword to the bit pattern of the int32, I'd get the number...

but I have no idea how to do that in PowerShell. (How can I do that?)

So I have to test for $x negative and if so use -$x-1 (because it's 2's complement).

Windows for home | Previous Windows versions | Apps

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2015-05-15T22:22:28+00:00

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-05-15T22:21:54+00:00

    https://social.msdn.microsoft.com/Forums/en-US/b970e780-0de0-4642-8ed6-576cbb3a5dd4/purpose-of-this-forum-this-forum-tells-you-where-to-go-ask-questions-please-read-before-posting?forum=whatforum

    wow , Microsoft sure provides crappy web pages for being a "great" software company

    That's a link to the top pinned article in the "Where is the forum for..." forum.

    Go there, click the forum title link, search for PowerShell

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-05-15T22:17:50+00:00

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-05-14T12:17:20+00:00

    Hello,

    Thank you for posting your question on Microsoft community.

    This issue better suits to the developers on MSDN forums.

    I would suggest you to post your question on MSDN forums.

    MSDN forum

    https://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages

    Thank you

    Was this answer helpful?

    0 comments No comments