TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Query shared folder free space

Microsoft Windows Powershell


Reply
 
Thread Tools Display Modes
Old 01-06-2008, 12:51 AM   #1
David Kriz
Guest
 
Posts: n/a
Query shared folder free space

Please,

how can I get free space in shared folder?

In "Cmd.exe" works this command:
/---------------------------------------------------------------\
C:\>dir \\bck01\backups
Volume in drive \\bck01\backups is Backups
Volume Serial Number is 0398-17C4

Directory of \\bck01\backups

31.05.2008 19:01 <DIR> .
21.07.2006 20:30 <DIR> ..
27.05.2008 04:27 <DIR> CTX01
27.05.2008 23:02 <DIR> CTX02
28.02.2008 17:51 <DIR> BCK01
21.07.2006 20:35 <DIR> EXC01
07.01.2008 00:57 <DIR> SQL01
0 File(s) 0 bytes
7 Dir(s) 10 214 379 520 bytes free

\_________________________________________________ ______________/

And "10 214 379 520" is this information which I need in my scripts.
  Reply With Quote
Old 01-06-2008, 03:53 AM   #2
Shay Levi
Guest
 
Posts: n/a
Re: Query shared folder free space


Try:

$dir = & cmd /c dir \\server\share
$size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+\s?)+)\sbytes').groups["size"].value
$size


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

> Please,
>
> how can I get free space in shared folder?
>
> In "Cmd.exe" works this command:
> /---------------------------------------------------------------\
> C:\>dir \\bck01\backups
> Volume in drive \\bck01\backups is Backups
> Volume Serial Number is 0398-17C4
> Directory of \\bck01\backups
>
> 31.05.2008 19:01 <DIR> .
> 21.07.2006 20:30 <DIR> ..
> 27.05.2008 04:27 <DIR> CTX01
> 27.05.2008 23:02 <DIR> CTX02
> 28.02.2008 17:51 <DIR> BCK01
> 21.07.2006 20:35 <DIR> EXC01
> 07.01.2008 00:57 <DIR> SQL01
> 0 File(s) 0 bytes
> 7 Dir(s) 10 214 379 520 bytes free
> \_________________________________________________ ______________/
>
> And "10 214 379 520" is this information which I need in my scripts.
>



  Reply With Quote
Old 01-06-2008, 08:51 PM   #3
Robert Aldwinckle
Guest
 
Posts: n/a
Re: Query shared folder free space

"Shay Levi" <no@addre.ss> wrote in message
news:95d808932e0178ca919675eaa590@news.microsoft.c om...

>> 0 File(s) 0 bytes



>
> Try:
>
> $dir = & cmd /c dir \\server\share



Looks like you need the /s switch on the dir command
for OP's example too?


> $size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+\s?)+)\sbytes').groups["size"].value



Assuming there was a typo and you meant: $dir[-2]?
So, the basis of the whole idea is to extract the second
last line and output the last numeric value in it?
Does that pattern not handle the possibility of commas
in the value field for some reason?

E.g., I was only able to get the regular expression to work
on sizes of less than 1000 (no commas). Even then I couldn't
get $size by itself to report anything. I haven't tried to parse it
out to try to figure out what all that syntax was supposed to do
(yet). ; )

ICIM this analysis was done on XPsp2 for Graphical PS
from PS 2 CTP 2.


TIA

Robert Aldwinckle
---


  Reply With Quote
Old 01-06-2008, 08:52 PM   #4
Robert Aldwinckle
Guest
 
Posts: n/a
Re: Query shared folder free space

"Robert Aldwinckle" <robald@techemail.com> wrote in message
news:eCUvpi$wIHA.4896@TK2MSFTNGP03.phx.gbl...
> "Shay Levi" <no@addre.ss> wrote in message
> news:95d808932e0178ca919675eaa590@news.microsoft.c om...
>


Oops. I just noticed the Subject: ...free space

so it was the last line he wanted.

And OP's example doesn't contain commas.

So, perhaps it all works as designed?

<voice actor="Emily Litella" Never mind! </voice>


---


>>> 0 File(s) 0 bytes

>
>
>>
>> Try:
>>
>> $dir = & cmd /c dir \\server\share

>
>
> Looks like you need the /s switch on the dir command
> for OP's example too?
>
>
>> $size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+\s?)+)\sbytes').groups["size"].value

>
>
> Assuming there was a typo and you meant: $dir[-2]?
> So, the basis of the whole idea is to extract the second
> last line and output the last numeric value in it?
> Does that pattern not handle the possibility of commas
> in the value field for some reason?
>
> E.g., I was only able to get the regular expression to work
> on sizes of less than 1000 (no commas). Even then I couldn't
> get $size by itself to report anything. I haven't tried to parse it
> out to try to figure out what all that syntax was supposed to do
> (yet). ; )
>
> ICIM this analysis was done on XPsp2 for Graphical PS
> from PS 2 CTP 2.
>
>
> TIA
>
> Robert Aldwinckle
> ---
>


  Reply With Quote
Old 02-06-2008, 12:52 AM   #5
Owen Gilmore
Guest
 
Posts: n/a
Re: Query shared folder free space


"David Kriz" <david.kriz@ccv.cz> wrote in message
news:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.gbl...
> Please,
>
> how can I get free space in shared folder?
>
> In "Cmd.exe" works this command:
> /---------------------------------------------------------------\
> C:\>dir \\bck01\backups
> Volume in drive \\bck01\backups is Backups
> Volume Serial Number is 0398-17C4
>
> Directory of \\bck01\backups
>
> 31.05.2008 19:01 <DIR> .
> 21.07.2006 20:30 <DIR> ..
> 27.05.2008 04:27 <DIR> CTX01
> 27.05.2008 23:02 <DIR> CTX02
> 28.02.2008 17:51 <DIR> BCK01
> 21.07.2006 20:35 <DIR> EXC01
> 07.01.2008 00:57 <DIR> SQL01
> 0 File(s) 0 bytes
> 7 Dir(s) 10 214 379 520 bytes free
>
> \_________________________________________________ ______________/
>
> And "10 214 379 520" is this information which I need in my scripts.


My first thought was to suggest WMI, which has a Win32_Share collection.
But that doesn't have a free space element in it. :-(

I'm a newb with powershell myself, and I did have time to do a lot of
research but did see anything built-in that addresses file sharing. It would
be a real shortcoming if it didn't have something built-in to at least match
WMI capability to administer file shares.... With WMI at least you can
create, enumerate shares, but not read or set aside free disk space for
it...

Good luck and let us know what you find!


  Reply With Quote
Old 02-06-2008, 01:49 AM   #6
Shay Levi
Guest
 
Posts: n/a
Re: Query shared folder free space



That's right

The free space is the last line (e.g $dir[-1]) + dir's free space on my computer
gives in a number with commas.
This is the regex I used on my computer, the only diffrence is a comma instead
of a space:

$size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes').groups["size"].value



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

> "Robert Aldwinckle" <robald@techemail.com> wrote in message
> news:eCUvpi$wIHA.4896@TK2MSFTNGP03.phx.gbl...
>
>> "Shay Levi" <no@addre.ss> wrote in message
>> news:95d808932e0178ca919675eaa590@news.microsoft.c om...

> Oops. I just noticed the Subject: ...free space
>
> so it was the last line he wanted.
>
> And OP's example doesn't contain commas.
>
> So, perhaps it all works as designed?
>
> <voice actor="Emily Litella" Never mind! </voice>
>
> ---
>
>>>> 0 File(s) 0 bytes
>>>>
>>> Try:
>>>
>>> $dir = & cmd /c dir \\server\share
>>>

>> Looks like you need the /s switch on the dir command for OP's
>> example too?
>>
>>> $size =
>>> [regex]::match($dir[-1],'\)\s+(?<size>(\d+\s?)+)\sbytes').groups["si
>>> ze"].value
>>>

>> Assuming there was a typo and you meant: $dir[-2]?
>> So, the basis of the whole idea is to extract the second
>> last line and output the last numeric value in it?
>> Does that pattern not handle the possibility of commas
>> in the value field for some reason?
>> E.g., I was only able to get the regular expression to work
>> on sizes of less than 1000 (no commas). Even then I couldn't
>> get $size by itself to report anything. I haven't tried to parse it
>> out to try to figure out what all that syntax was supposed to do
>> (yet). ; )
>> ICIM this analysis was done on XPsp2 for Graphical PS from PS 2
>> CTP 2.
>>
>> TIA
>>
>> Robert Aldwinckle
>> ---



  Reply With Quote
Old 02-06-2008, 03:53 AM   #7
Robert Aldwinckle
Guest
 
Posts: n/a
Re: Query shared folder free space

"Shay Levi" <no@addre.ss> wrote in message
news:95d808932e0c38ca925140c8a6d0@news.microsoft.c om...
>
>
> That's right
>
> The free space is the last line (e.g $dir[-1]) + dir's free space on my computer
> gives in a number with commas.
> This is the regex I used on my computer, the only diffrence is a comma instead
> of a space:
>
> $size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes').groups["size"].value



Thanks. In fact, I got that far myself but I still don't get
any sense that the group name is working.
I'm assuming that gives a kind of associative lookup
instead of an indexed lookup for the list of named
matches that the match creates? So, should there
be a Regex.ExplicitCapture option applied to it somehow?
I already tried doing that with a Regex constructor
inside the match function but that didn't work.

To try to help understand this I simplified the definition of $dir
edited the $size definition, left the pattern as it was and
listed its properties:

$dir = '7 Dir(s) 10 214 379 520 bytes free'
[regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes')


Groups : {) 10 214 379 520 bytes, 520, 10 214 379 520}
Success : True
Captures : {) 10 214 379 520 bytes}
Index : 7
Length : 23
Value : ) 10 214 379 520 bytes

Is the <size> group name supposed to show up in that list?
Otherwise how can it be extracted from Groups?
Or does the match() method externalize such names somehow?
In that case that really isn't obvious from any of the documentation
I have seen so far and in any case is not working in my environment.

Note that using the explicit index groups[2] does work
but I don't know how reliable this would be in general
for this application:

$size = [regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes').gro ups[2].value

I guess my next tack to understanding what is going on
will have to be putting a trace on that match function
and seeing what I can glean that way...


Thanks again.

Robert
---


  Reply With Quote
Old 02-06-2008, 07:56 PM   #8
Shay Levi
Guest
 
Posts: n/a
Re: Query shared folder free space


Hi Robert,

I can't find any good explanation why named groups names are not available
on $size.
Btw, they are also avaiable using the Item member:

#http://msdn.microsoft.com/en-us/library/hchbwda2.aspx
PS > $dir = & cmd /c dir d:\
PS > $size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes')
PS > $size.groups.item("size").value
6,010,818,560



Another alternative would be to use the -match operator. That way named groups
become available as members on $matches:

PS > $dir = & cmd /c dir d:\
PS > $dir[-1] -match '\)\s+(?<size>(\d+,?)+)\sbytes'
True

PS > $matches

Name Value
---- -----
size 6,011,998,208
1 208
0 ) 6,011,998,208 bytes

PS > $matches.size
6,011,998,208




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

> "Shay Levi" <no@addre.ss> wrote in message
> news:95d808932e0c38ca925140c8a6d0@news.microsoft.c om...
>> That's right
>>
>> The free space is the last line (e.g $dir[-1]) + dir's free space on
>> my computer
>> gives in a number with commas.
>> This is the regex I used on my computer, the only diffrence is a
>> comma instead
>> of a space:
>> $size =
>> [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes').groups["size
>> "].value
>>

> Thanks. In fact, I got that far myself but I still don't get
> any sense that the group name is working.
> I'm assuming that gives a kind of associative lookup
> instead of an indexed lookup for the list of named
> matches that the match creates? So, should there
> be a Regex.ExplicitCapture option applied to it somehow?
> I already tried doing that with a Regex constructor
> inside the match function but that didn't work.
> To try to help understand this I simplified the definition of $dir
> edited the $size definition, left the pattern as it was and
> listed its properties:
> $dir = '7 Dir(s) 10 214 379 520 bytes free'
> [regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes')
> Groups : {) 10 214 379 520 bytes, 520, 10 214 379 520}
> Success : True
> Captures : {) 10 214 379 520 bytes}
> Index : 7
> Length : 23
> Value : ) 10 214 379 520 bytes
> Is the <size> group name supposed to show up in that list?
> Otherwise how can it be extracted from Groups?
> Or does the match() method externalize such names somehow?
> In that case that really isn't obvious from any of the documentation
> I have seen so far and in any case is not working in my environment.
> Note that using the explicit index groups[2] does work but I don't
> know how reliable this would be in general for this application:
>
> $size =
> [regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes').gro ups[2].value
>
> I guess my next tack to understanding what is going on will have to be
> putting a trace on that match function and seeing what I can glean
> that way...
>
> Thanks again.
>
> Robert
> ---



  Reply With Quote
Old 02-06-2008, 09:47 PM   #9
Tao Ma
Guest
 
Posts: n/a
Re: Query shared folder free space

Hi Robert,

I find some remarks on the MSDN:

Namespace: System.Text.RegularExpressions
Match Class
Because a single match can involve multiple capturing groups, Match has a
Group property that returns the GroupCollection. The GroupCollection has
accessors that return each group. Match inherits from Group so the entire
substring matched can be accessed directly. That is, the Match instance
itself is equivalent to Match.Groups[0] (Match.Groups(0) in Visual Basic).
The Match object is immutable and has no public constructor.

Tao Ma


"Robert Aldwinckle" <robald@techemail.com> 写入消息新闻:E1214F84-7CB1-4A38-8287-5D1E8CA5DA2B@microsoft.com...
> "Shay Levi" <no@addre.ss> wrote in message
> news:95d808932e0c38ca925140c8a6d0@news.microsoft.c om...
>>
>>
>> That's right
>>
>> The free space is the last line (e.g $dir[-1]) + dir's free space on my
>> computer
>> gives in a number with commas.
>> This is the regex I used on my computer, the only diffrence is a comma
>> instead
>> of a space:
>>
>> $size =
>> [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes').groups["size"].value

>
>
> Thanks. In fact, I got that far myself but I still don't get
> any sense that the group name is working.
> I'm assuming that gives a kind of associative lookup
> instead of an indexed lookup for the list of named
> matches that the match creates? So, should there
> be a Regex.ExplicitCapture option applied to it somehow?
> I already tried doing that with a Regex constructor
> inside the match function but that didn't work.
>
> To try to help understand this I simplified the definition of $dir
> edited the $size definition, left the pattern as it was and
> listed its properties:
>
> $dir = '7 Dir(s) 10 214 379 520 bytes free'
> [regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes')
>
>
> Groups : {) 10 214 379 520 bytes, 520, 10 214 379 520}
> Success : True
> Captures : {) 10 214 379 520 bytes}
> Index : 7
> Length : 23
> Value : ) 10 214 379 520 bytes
>
> Is the <size> group name supposed to show up in that list?
> Otherwise how can it be extracted from Groups?
> Or does the match() method externalize such names somehow?
> In that case that really isn't obvious from any of the documentation
> I have seen so far and in any case is not working in my environment.
>
> Note that using the explicit index groups[2] does work
> but I don't know how reliable this would be in general
> for this application:
>
> $size =
> [regex]::match($dir,'\)\s+(?<size>(\d+\s?)+)\sbytes').gro ups[2].value
>
> I guess my next tack to understanding what is going on
> will have to be putting a trace on that match function
> and seeing what I can glean that way...
>
>
> Thanks again.
>
> Robert
> ---
>



  Reply With Quote
Old 03-06-2008, 12:54 AM   #10
Robert Aldwinckle
Guest
 
Posts: n/a
Re: Query shared folder free space

"Shay Levi" <no@addre.ss> wrote in message
news:89228ed22e2718ca92ea64716d76@news.microsoft.c om...
>
> Hi Robert,
>
> I can't find any good explanation why named groups names
> are not available on $size.



It appears to be a difference between using the GWPS and PS
(CTP 2). I couldn't reproduce my problem symptom in the normal
shell.


> Btw, they are also avaiable using the Item member:
>
> #http://msdn.microsoft.com/en-us/library/hchbwda2.aspx
> PS > $dir = & cmd /c dir d:\
> PS > $size = [regex]::match($dir[-1],'\)\s+(?<size>(\d+,?)+)\sbytes')
> PS > $size.groups.item("size").value
> 6,010,818,560



That one doesn't work in either PS or GWPS (CTP 2)

In both I get this error message:

$size.groups.item("size").value
You cannot call a method on a null-valued expression.
At line:1 char:18
+ $size.groups.item <<<< ("size").value


>
>
>
> Another alternative would be to use the -match operator.
> That way named groups become available as members on $matches:
>
> PS > $dir = & cmd /c dir d:\
> PS > $dir[-1] -match '\)\s+(?<size>(\d+,?)+)\sbytes'
> True
>
> PS > $matches
>
> Name Value
> ---- -----
> size 6,011,998,208
> 1 208
> 0 ) 6,011,998,208 bytes
>
> PS > $matches.size
> 6,011,998,208



Yes. That one works in both environments.

I'll guess I'll have to try tracing both cases
and compare the traces?

Maybe it's not such a great idea trying to *learn* PS
on a beta version... <eg>


Thanks again.

Robert
---


  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 09:24 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional