Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - DriveInfo in GBs and calculate used space in GBs, in Percent

Reply
 
Old 01-11-2008   #1 (permalink)
Gregor


 
 

DriveInfo in GBs and calculate used space in GBs, in Percent

Hello

I would like DriveInfos in GBs and calculate used space

I have:

$drives = [System.IO.DriveInfo]::GetDrives()
$drives | where {$_.DriveType -eq "Fixed"} | Format-Table Name,
TotalFreeSpace, TotalSize -auto

Output:

Name TotalFreespace TotalSize
C:\ 63851022848 72818371072

The new Output

Name, Freespace in GBs, TotalSize in GBs, Freespace in %, UsedSpace %

Thanks for any help

Gregor


My System SpecsSystem Spec
Old 01-11-2008   #2 (permalink)
Shay Levi


 
 

Re: DriveInfo in GBs and calculate used space in GBs, in Percent


Try:


$FreeGB = @{label="Free (GB)";expression={"{0:N2}" -f ($_.TotalFreeSpace/1gb)}}
$TotalSizeGB = @{label="TotalSize (GB)";expression={"{0:N2}" -f ($_.TotalSize/1gb)}}
$PFreespace = @{label="% Free";expression={"{0:P2}" -f ($_.TotalFreeSpace/$_.TotalSize)}}
$PUsedSpace = @{label="% UsedSpace";expression={"{0:P2}" -f (($_.TotalSize-$_.TotalFreeSpace)/$_.TotalSize)}}

[System.IO.DriveInfo]::GetDrives() | where {$_.DriveType -eq "Fixed"} | ft
name,$FreeGB,$TotalSizeGB,$PFreespace,$PUsedSpace -auto




-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hello
>
> I would like DriveInfos in GBs and calculate used space
>
> I have:
>
> $drives = [System.IO.DriveInfo]::GetDrives()
> $drives | where {$_.DriveType -eq "Fixed"} | Format-Table Name,
> TotalFreeSpace, TotalSize -auto
> Output:
>
> Name TotalFreespace TotalSize
> C:\ 63851022848 72818371072
> The new Output
>
> Name, Freespace in GBs, TotalSize in GBs, Freespace in %, UsedSpace %
>
> Thanks for any help
>
> Gregor
>

My System SpecsSystem Spec
Old 01-11-2008   #3 (permalink)
Gregor


 
 

Re: DriveInfo in GBs and calculate used space in GBs, in Percent

Hello Shay

Thanks

I have problems with name

Error message: The term 'name' is not recognized as a cmdlet, function,
operable program

Do you have a idea?

Thanks
Gregor


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a94418eb48ca224f09def646@xxxxxx
Quote:

>
> Try:
>
>
> $FreeGB = @{label="Free (GB)";expression={"{0:N2}" -f
> ($_.TotalFreeSpace/1gb)}}
> $TotalSizeGB = @{label="TotalSize (GB)";expression={"{0:N2}" -f
> ($_.TotalSize/1gb)}}
> $PFreespace = @{label="% Free";expression={"{0:P2}" -f
> ($_.TotalFreeSpace/$_.TotalSize)}}
> $PUsedSpace = @{label="% UsedSpace";expression={"{0:P2}" -f
> (($_.TotalSize-$_.TotalFreeSpace)/$_.TotalSize)}}
>
> [System.IO.DriveInfo]::GetDrives() | where {$_.DriveType -eq "Fixed"} | ft
> name,$FreeGB,$TotalSizeGB,$PFreespace,$PUsedSpace -auto
>
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> Hello
>>
>> I would like DriveInfos in GBs and calculate used space
>>
>> I have:
>>
>> $drives = [System.IO.DriveInfo]::GetDrives()
>> $drives | where {$_.DriveType -eq "Fixed"} | Format-Table Name,
>> TotalFreeSpace, TotalSize -auto
>> Output:
>>
>> Name TotalFreespace TotalSize
>> C:\ 63851022848 72818371072
>> The new Output
>>
>> Name, Freespace in GBs, TotalSize in GBs, Freespace in %, UsedSpace %
>>
>> Thanks for any help
>>
>> Gregor
>>
>
>
My System SpecsSystem Spec
Old 01-11-2008   #4 (permalink)
Kirk Munro [MVP]


 
 

Re: DriveInfo in GBs and calculate used space in GBs, in Percent

The last two lines of Shay's script are actually one line, wrapped. Make
that one line and you should be good to go.

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com


"Gregor" <nospam@xxxxxx> wrote in message
news:801AC0B9-488C-4144-9A1D-87562DC987DF@xxxxxx
Quote:

> Hello Shay
>
> Thanks
>
> I have problems with name
>
> Error message: The term 'name' is not recognized as a cmdlet, function,
> operable program
>
> Do you have a idea?
>
> Thanks
> Gregor
>
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a94418eb48ca224f09def646@xxxxxx
Quote:

>>
>> Try:
>>
>>
>> $FreeGB = @{label="Free (GB)";expression={"{0:N2}" -f
>> ($_.TotalFreeSpace/1gb)}}
>> $TotalSizeGB = @{label="TotalSize (GB)";expression={"{0:N2}" -f
>> ($_.TotalSize/1gb)}}
>> $PFreespace = @{label="% Free";expression={"{0:P2}" -f
>> ($_.TotalFreeSpace/$_.TotalSize)}}
>> $PUsedSpace = @{label="% UsedSpace";expression={"{0:P2}" -f
>> (($_.TotalSize-$_.TotalFreeSpace)/$_.TotalSize)}}
>>
>> [System.IO.DriveInfo]::GetDrives() | where {$_.DriveType -eq "Fixed"} |
>> ft name,$FreeGB,$TotalSizeGB,$PFreespace,$PUsedSpace -auto
>>
>>
>>
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
>>
Quote:

>>> Hello
>>>
>>> I would like DriveInfos in GBs and calculate used space
>>>
>>> I have:
>>>
>>> $drives = [System.IO.DriveInfo]::GetDrives()
>>> $drives | where {$_.DriveType -eq "Fixed"} | Format-Table Name,
>>> TotalFreeSpace, TotalSize -auto
>>> Output:
>>>
>>> Name TotalFreespace TotalSize
>>> C:\ 63851022848 72818371072
>>> The new Output
>>>
>>> Name, Freespace in GBs, TotalSize in GBs, Freespace in %, UsedSpace %
>>>
>>> Thanks for any help
>>>
>>> Gregor
>>>
>>
>>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Calculate copy time VB Script
how to calculate the system uptime VB Script
Calculate sum PowerShell
How to use http://servername as the DriveInfo.Root? ...a more basic question PowerShell
Calculate % of CPU time for every active process PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46