Windows Vista Forums

Completely easy question - Division
  1. #1



    Newbie
    Join Date : Apr 2008
    Posts : 5
    :P
    Local Time: 11:54 PM

    Completely easy question - Division

    I feel like an idiot - I can't figure this one out.
    I'm extremely new to Powershell, and even scripting in general.

    I can't figure out how to do this:



    $pct = $DiskDrive.FreeSpace /= $DiskDrive.Size
    It doesn't work as / either.

    The operation '[System.UInt64] /= [System.UInt64]' is not defined.
    At C:\powershell\Test Scripts\freespace2.ps1:7 char:31
    + $pct = $DiskDrive.FreeSpace /= <<<< $DiskDrive.Size

    From what I can tell /= will divide the objects' values.
    Am I using this incorrectly? I just want a percentage of freespace

    Thanks!!

      My System SpecsSystem Spec

  2. #2


    Oisin (x0n) Grehan [MVP] Guest

    Re: Completely easy question - Division

    On Apr 4, 11:45*am, bradn901cb <bradn901cb.37c...@xxxxxx-mx.forums.net>
    wrote:

    > I feel like an idiot - I can't figure this one out.
    > I'm extremely new to Powershell, and even scripting in general.
    >
    > I can't figure out how to do this:
    >
    > $pct = $DiskDrive.FreeSpace /= $DiskDrive.Size
    > It doesn't work as / either.
    >
    > The operation '[System.UInt64] /= [System.UInt64]' is not defined.
    > At C:\powershell\Test Scripts\freespace2.ps1:7 char:31
    > + $pct = $DiskDrive.FreeSpace /= <<<< *$DiskDrive.Size
    >
    > From what I can tell /= will divide the objects' values.
    > Am I using this incorrectly? *I just want a percentage of freespace
    >
    > Thanks!!
    >
    > --
    > bradn901cb
    Hey,

    Use / instead, not /=. The latter is a combined divide-and-assign
    operator, much like +=, -= and *=. The latter is used like:

    instead of:

    $x = 10
    $x = $x / 2

    use:

    $x = 10
    $x /= 2

    So effectively saving yourself the extra typing.

    - Oisin





      My System SpecsSystem Spec

  3. #3


    Marco Shaw [MVP] Guest

    Re: Completely easy question - Division

    bradn901cb wrote:

    > I feel like an idiot - I can't figure this one out.
    > I'm extremely new to Powershell, and even scripting in general.
    >
    > I can't figure out how to do this:
    >
    > $pct = $DiskDrive.FreeSpace /= $DiskDrive.Size
    > It doesn't work as / either.
    >
    > The operation '[System.UInt64] /= [System.UInt64]' is not defined.
    > At C:\powershell\Test Scripts\freespace2.ps1:7 char:31
    > + $pct = $DiskDrive.FreeSpace /= <<<< $DiskDrive.Size
    As Oisin mentions, and also:
    http://groups.google.com/group/micro...0e46fd41ccdf93

    Marco

    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com

      My System SpecsSystem Spec

  4. #4


    Kiron Guest

    Re: Completely easy question - Division

    It's a bug that will be fixed in v2. To work around it cast either, or both, [uInt64] to [long], [decimal], [single] or [double]:

    $DiskDrive = gwmi win32_logicaldisk -f "Name='c:'"
    $DiskDrive.FreeSpace / [long]$DiskDrive.Size
    [long]$DiskDrive.FreeSpace / $DiskDrive.Size
    [long]$DiskDrive.FreeSpace / [long]$DiskDrive.Size

    --
    Kiron

      My System SpecsSystem Spec

  5. #5



    Newbie
    Join Date : Apr 2008
    Posts : 5
    :P
    Local Time: 11:54 PM


      Thread Starter

    Re: Completely easy question - Division

    Thank you!
    The [long] is exactly what I needed.

      My System SpecsSystem Spec

Completely easy question - Division problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
easy question muz1234 General Discussion 2 15 Mar 2010
escape character question - hopefully an easy question Cookiecutter PowerShell 2 29 Jan 2009
Easy question jason PowerShell 2 12 May 2008
One easy question.. irish-grouse Vista installation & setup 6 08 May 2007
UInt64 division Thomy Kay PowerShell 6 08 Mar 2007