Division by 1GB generating 'op_Division' error message

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ben Crane Ben Crane 11 months ago.

  • Author
    Posts
  • #33868
    Profile photo of Ben Crane
    Ben Crane
    Participant

    Hi,

    Just delving into PS and I'm finding a little bit of inconsistency with how the / 1GB is working:

    Currently I have:

    $disk = Get-WmiObject Win32_logicaldisk
    $diskfreesize = $disk.FreeSpace / 1GB

    On some machines this works very nicely, no errors, but on others I get the

    Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Division'.
    At ....
    + $diskfreesize = $diskfreesize_raw / 1GB
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    Can anyone help me understand why this is happening? Is it different PS versions?

    Cheers
    Ben

  • #33869
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Which of the 2 lines are you running

    $diskfreesize = $disk.FreeSpace / 1GB
    or
    $diskfreesize = $diskfreesize_raw / 1GB

    Which versions of PowerShell are you running?
    Do the disks that fail actually have any free space eg if its a CD it doesn't report any free space

  • #33870
    Profile photo of Ben Crane
    Ben Crane
    Participant

    Hi Richard,

    Not sure if my last post made it – still can't see it.

    Your questions made me realised there was a seperate drive which was causing the problems and I didn't specify a filter to only look at C: drive!

    Thank you for you help – rookie error

You must be logged in to reply to this topic.