Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Free Disk Space on network share

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-29-2007   #1 (permalink)
Clint Bodine
Guest


 

Free Disk Space on network share

Hello,

I have a cmd.exe batch script (a one-liner, actually) which returns
the amount of free disk space on each share of a network drive. The
core of the line is dir \\server\share1 | grep free. (Basically the
same as Unix grep. I'm not sure where it came from, but its there).

Anyway, I want to do this in Powershell instead. But Dir is just an
alias for Get-ChildItem and doesn't say anything about free disk
space. I also looked at Get-Item, but System.IO.DirectoryInfo doesn't
seem to be aware of the free space either. Get-WMIObject is out
because the share is on a Netapp. (I got a message saying that the RPC
server isn't available). I don't really want to use WMI anyway since
this information *SHOULD* (IMO) be available to Powershell directly.
And I can't figure out how to run cmd's 'dir' command from Powershell
either.

Anyone have any ideas? Thanks!


My System SpecsSystem Spec
Old 03-29-2007   #2 (permalink)
Clint Bodine
Guest


 

Re: Free Disk Space on network share

Oh... I guess I do have access to "dir":

(cmd /c "dir") -match "bytes free"

But this is pretty lame. There has to be a better way.

Any thoughts?

Clint Bodine wrote:
> Hello,
>
> I have a cmd.exe batch script (a one-liner, actually) which returns
> the amount of free disk space on each share of a network drive. The
> core of the line is dir \\server\share1 | grep free. (Basically the
> same as Unix grep. I'm not sure where it came from, but its there).
>
> Anyway, I want to do this in Powershell instead. But Dir is just an
> alias for Get-ChildItem and doesn't say anything about free disk
> space. I also looked at Get-Item, but System.IO.DirectoryInfo doesn't
> seem to be aware of the free space either. Get-WMIObject is out
> because the share is on a Netapp. (I got a message saying that the RPC
> server isn't available). I don't really want to use WMI anyway since
> this information *SHOULD* (IMO) be available to Powershell directly.
> And I can't figure out how to run cmd's 'dir' command from Powershell
> either.
>
> Anyone have any ideas? Thanks!


My System SpecsSystem Spec
Old 03-29-2007   #3 (permalink)
Gaurhoth
Guest


 

Re: Free Disk Space on network share

Try:

# Assumes V: does not already exists

$map = new-Object -com Wscript.Network

$map.MapNetworkDrive("v:","\\$computer\c$")

$fso = new-Object -com Scripting.FileSystemObject

$do = $fso.getdrive("v")

$do.AvailableSpace

$do.TotalSize



# to see everything this object offers

$do |Format-List *



$map.RemoveNetworkDrive("v:")


Gaurhoth
http://thepowershellguy.com/blogs/gaurhoth/


"Clint Bodine" <csbodine@gmail.com> wrote in message news:1175186175.831882.84390@e65g2000hsc.googlegroups.com...
> Oh... I guess I do have access to "dir":
>
> (cmd /c "dir") -match "bytes free"
>
> But this is pretty lame. There has to be a better way.
>
> Any thoughts?
>
> Clint Bodine wrote:
>> Hello,
>>
>> I have a cmd.exe batch script (a one-liner, actually) which returns
>> the amount of free disk space on each share of a network drive. The
>> core of the line is dir \\server\share1 | grep free. (Basically the
>> same as Unix grep. I'm not sure where it came from, but its there).
>>
>> Anyway, I want to do this in Powershell instead. But Dir is just an
>> alias for Get-ChildItem and doesn't say anything about free disk
>> space. I also looked at Get-Item, but System.IO.DirectoryInfo doesn't
>> seem to be aware of the free space either. Get-WMIObject is out
>> because the share is on a Netapp. (I got a message saying that the RPC
>> server isn't available). I don't really want to use WMI anyway since
>> this information *SHOULD* (IMO) be available to Powershell directly.
>> And I can't figure out how to run cmd's 'dir' command from Powershell
>> either.
>>
>> Anyone have any ideas? Thanks!

>

My System SpecsSystem Spec
Old 04-01-2007   #4 (permalink)
Jacques Barathon [MS]
Guest


 

Re: Free Disk Space on network share

"Gaurhoth" <gaurhoth@live.com> wrote in message
news:OwP644ncHHA.4032@TK2MSFTNGP02.phx.gbl...
> Try:
>
> # Assumes V: does not already exists
> $map = new-Object -com Wscript.Network
> $map.MapNetworkDrive("v:","\\$computer\c$")
> $fso = new-Object -com Scripting.FileSystemObject
> $do = $fso.getdrive("v")
> $do.AvailableSpace
> $do.TotalSize


You don't even need to map the drive first:

$do = $fso.getdrive("\\$computer\c$")

.... will work equally.

Or as a one-liner:

(new-object -com
scripting.filesystemobject).getdrive("\\computer\c$").availablespace

Jacques

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Misreported Used/Free Disk Space Shade_C Vista General 3 04-17-2008 07:11 AM
Out of disk space error at installations, though 100 Gb free space Evagoud Vista General 5 11-04-2007 02:48 AM
free disk space is reduced while copying over network joseph millman Vista file management 0 10-12-2007 12:18 PM
free disk space is reduced while copying over network joseph millman Vista networking & sharing 0 10-12-2007 12:18 PM
free disk space is reduced while copying over network joseph millman Vista performance & maintenance 0 10-12-2007 12:18 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51