header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Truncate??
Last Post 29 Jan 2008 08:27 PM by biorchang. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
biorchangUser is Offline
New Member
New Member
Posts:10
Avatar

--
29 Jan 2008 05:19 PM  

Hi All.

Having trouble finding the right term here.  I am using WMI Win32_LogicalDisk to get the disk drive information.

I want to get the size and display it, but only the value on the left of the decimal point.  Right now I am getting values like:

 

124.2135546876546864

 

I am using:

 

$strDiskItems = get-wmiobject -credential $Cred -class "Win32_LogicalDisk" -namespace "root\CIMV2" `
     -computername $strComputer -filter "DriveType=3"
      
      $Put = ""

      foreach ($objitem in $strDiskItems) {

       $Cap = $objItem.Caption
       $Size = $objItem.Size/1024/1024/1024
       $Free = $objItem.FreeSpace/1024/1024/1024
       $Put = $Put + $Cap + $Free + "/" + $Size
       $WS.Cells.Item($count,8) = $Put
       }

 

Any way to do this?  Some kind of built in truncate or math function?

 

Thanks!

bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
29 Jan 2008 05:38 PM  
Perhaps this will do it for you

$strDiskItems = get-wmiobject -credential $Cred -class "Win32_LogicalDisk" -namespace "root\CIMV2" `
-computername $strComputer -filter "DriveType=3"

$Put = ""

foreach ($objitem in $strDiskItems) {

$Cap = $objItem.Caption
$Size = "{0:n2}GB" -f ($objItem.Size/1gb)
$Free = "{0:n2}GB" -f ($objItem.FreeSpace/1gb)
$Put = $Put + $Cap + $Free + "/" + $Size
$WS.Cells.Item($count,8) = $Put
}

This uses the -f operator... more info here http://bsonposh.com/modules/wordpress/?p=35
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
29 Jan 2008 06:47 PM  
To highlight something Brandon shows above, "GB" is a special keyword when used adjacent to a numeric value. "MB" works similarly. But the value will show several decimal places without the -f stuff.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
biorchangUser is Offline
New Member
New Member
Posts:10
Avatar

--
29 Jan 2008 08:27 PM  
Awesome. That did the trick.. Thanks all...
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer