Completely easy question - Division

B

bradn901cb

Guest
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
 


On Apr 4, 11:45 am, bradn901cb <bradn901cb.37c...@no-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




 
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/micr...6fd41ccdf93?lnk=gst&q=uint64#b30e46fd41ccdf93

Marco

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

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

Blog:
http://marcoshaw.blogspot.com
 
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
 
Thank you!
The [long] is exactly what I needed.


--
bradn901cb

Brad
I dunno what I am doing.
 

Back
Top