![]() |
![]() |
|
|||||||
| Register | Forum Rules | Getting Started! - Guide | Blog | Videos | Gallery | Members List | Social Groups | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
> That one doesn't work in either PS or GWPS (CTP 2) I tested it on: 1. W3K + PoSH v1 2. XP SP2 + PoSH CTP 3. Vista SP1 + PoSH CTP2 All worked with no errors. What do you get for $size.groups (do you have a d:\ drive)? --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com > "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 > --- |
|
|
|
#12 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Oh... on GWPS too.
--- Shay Levi $cript Fanatic http://scriptolog.blogspot.com >> That one doesn't work in either PS or GWPS (CTP 2) >> > I tested it on: > > 1. W3K + PoSH v1 > 2. XP SP2 + PoSH CTP > 3. Vista SP1 + PoSH CTP2 > All worked with no errors. What do you get for $size.groups (do you > have a d:\ drive)? > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com >> "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 >> --- |
|
|
|
#13 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
"Tao Ma" <feng_eden@163.com> wrote in message
news:#YzDmiMxIHA.420@TK2MSFTNGP02.phx.gbl... > Hi Robert, > > I find some remarks on the MSDN: > > Namespace: System.Text.RegularExpressions > Match Class .... I found one which also shows this: <extract> Assembly: System (in system.dll) </extract> So I did a search for that module. How do I find out which one is being used and whether GWPS is using a different one from PS CTP 2? <cmd_output> F:\>dir/s system.dll Volume in drive F has no label. Volume Serial Number is D4EA-7B87 Directory of F:\WINDOWS\assembly\GAC\System\1.0.5000.0__b77a5c5 61934e089 2007-07-16 13:04 1,232,896 System.dll 1 File(s) 1,232,896 bytes Directory of F:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5 c561934e089 2008-04-09 17:31 3,076,096 System.dll 1 File(s) 3,076,096 bytes Directory of F:\WINDOWS\assembly\NativeImages1_v1.1.4322\System \1.0.5000.0__b77a5c561934e089_63e96c4b 2007-07-16 13:07 4,788,224 System.dll 1 File(s) 4,788,224 bytes Directory of F:\WINDOWS\assembly\NativeImages1_v1.1.4322\System \1.0.5000.0__b77a5c561934e089_6e11cc66 2007-07-16 13:05 1,966,080 System.dll 1 File(s) 1,966,080 bytes Directory of F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 2007-04-13 21:35 1,232,896 System.dll 1 File(s) 1,232,896 bytes Directory of F:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 2007-10-24 01:47 3,076,096 System.dll 1 File(s) 3,076,096 bytes Total Files Listed: 6 File(s) 15,372,288 bytes </cmd_output> ; ) Thanks. Robert --- |
|
|
|
#14 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi Robert,
Try: PS C:\> [Appdomain]::CurrentDomain.GetAssemblies() | ? {$_.ManifestModule -like 'system.dll'} GAC Version Location --- ------- -------- True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5 c561934e089\System.dll Tao Ma "Robert Aldwinckle" <robald@techemail.com> 写入消息新闻:%23tNenRPxIHA.3384@TK2MSFTNGP03.phx.g bl... > "Tao Ma" <feng_eden@163.com> wrote in message > news:#YzDmiMxIHA.420@TK2MSFTNGP02.phx.gbl... >> Hi Robert, >> >> I find some remarks on the MSDN: >> >> Namespace: System.Text.RegularExpressions >> Match Class > ... > > > I found one which also shows this: > > <extract> > Assembly: System (in system.dll) > </extract> > > So I did a search for that module. > How do I find out which one is being used > and whether GWPS is using a different one > from PS CTP 2? > > > <cmd_output> > F:\>dir/s system.dll > Volume in drive F has no label. > Volume Serial Number is D4EA-7B87 > > Directory of F:\WINDOWS\assembly\GAC\System\1.0.5000.0__b77a5c5 61934e089 > > 2007-07-16 13:04 1,232,896 System.dll > 1 File(s) 1,232,896 bytes > > Directory of F:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5 c561934e089 > > 2008-04-09 17:31 3,076,096 System.dll > 1 File(s) 3,076,096 bytes > > Directory of > F:\WINDOWS\assembly\NativeImages1_v1.1.4322\System \1.0.5000.0__b77a5c561934e089_63e96c4b > > 2007-07-16 13:07 4,788,224 System.dll > 1 File(s) 4,788,224 bytes > > Directory of > F:\WINDOWS\assembly\NativeImages1_v1.1.4322\System \1.0.5000.0__b77a5c561934e089_6e11cc66 > > 2007-07-16 13:05 1,966,080 System.dll > 1 File(s) 1,966,080 bytes > > Directory of F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 > > 2007-04-13 21:35 1,232,896 System.dll > 1 File(s) 1,232,896 bytes > > Directory of F:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 > > 2007-10-24 01:47 3,076,096 System.dll > 1 File(s) 3,076,096 bytes > > Total Files Listed: > 6 File(s) 15,372,288 bytes > </cmd_output> > > > ; ) > > > Thanks. > > Robert > --- > |
|
|
|
#15 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Thank's You all very much for help!
:-) I tested our solution with regular expression. Unfortunately it probably depends on language version of operatin system (I must use both English and Czech). :-( So that I must developed this solution: /---------------------------------------------------------------\ Function FreeBytesInSharedFolder { param ( [string]$piFolder ) [single]$RetVal = -1 if (Test-Path $piFolder) { $DirOutput = & cmd.exe /c dir $piFolder $StringWithNumber = $DirOutput[-1] $X = $StringWithNumber.split(":") $StringWithNumber = $X[2] $AscCode = [byte] [string]$Digits = "0" for ($I = 0; $I -le $StringWithNumber.Length; $I++) { $AscCode = [byte][char] $StringWithNumber[$I] if (($AscCode -gt 47) -and ($AscCode -lt 57)) { $Digits += $StringWithNumber[$I] } } $RetVal = [single]$Digits } $RetVal } \_________________________________________________ ______________/ David Kriz wrote: > 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. |
|
|
|
#16 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi David,
I just write a painful code to query shared folder free space. Please do not mind my poor English. I'm not a native Speaker. Firstly, I tried to use System.IO.DriveInfo to solve this problem. But I realize that it doesn't accept UNC format as its parameter. Then I noticed that GetDiskFreeSpace can be used here. I don't know how to call a win32 api in PowerShell at all yesterday... There is post on the PowerShell Team Blog which introduce "Show-PowerShell / Hide-PowerShell". After I read it, I know I can call GetDiskFreeSpace in PowerShell.... # Just declare Win32 API... $a = Add-Type -memberDefinition @" [DllImport("Kernel32.dll")] public static extern bool GetDiskFreeSpaceEx( string lpDirectoryName, IntPtr lpFreeBytesAvailable, IntPtr lpTotalNumberOfBytes, IntPtr lpTotalNumberOfFreeBytes ); "@ -passthru -name MyGetDiskFreeSpaceEx # Alloc some memory ... $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); # Call 'GetDiskFreeSpaceEx' ... $a::GetDiskFreeSpaceEx("\\.host\Shared Folders\files", $fba, $tnb, $nfb) # Get the Value storing in the memory pointed by $fba... $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) # Display the result ... "FreeBytesAvailable: $($x)" "TotalNumberOfBytes: $($y)" "TotalNumberOfFreeBytes: $($z)" # !! Free the memory ASAP.... [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); I know this is really painful...But I just Call a Win32 API in PowerShell. And I have to say PowerShell is really really really Powerfullllllll............ Tao Ma "David Kriz" <david.kriz@ccv.cz> 写入消息新闻:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.g bl... > 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. |
|
|
|
#17 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi Mao You can try this, it's a PowerShell cross-version code: [io.driveinfo]::getdrives() and based on the result, get the free space for fixed drives: [io.driveinfo]::getdrives() | where {$_.DriveType -eq "Fixed"} | select Name,AvailableFreeSpace There's is also the wmi option: gwmi Win32_LogicalDisk | where {$_.DriveType -eq 3} | select deviceID,FreeSpace --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com > Hi David, > > I just write a painful code to query shared folder free space. Please > do not mind my poor English. I'm not a native Speaker. > > Firstly, I tried to use System.IO.DriveInfo to solve this problem. But > I realize that it doesn't accept UNC format as its parameter. > > Then I noticed that GetDiskFreeSpace can be used here. I don't know > how to call a win32 api in PowerShell at all yesterday... > > There is post on the PowerShell Team Blog which introduce > "Show-PowerShell / > Hide-PowerShell". After I read it, I know I can call > GetDiskFreeSpace in PowerShell.... > # Just declare Win32 API... > $a = Add-Type -memberDefinition @" > [DllImport("Kernel32.dll")] > public static extern bool GetDiskFreeSpaceEx( > string lpDirectoryName, > IntPtr lpFreeBytesAvailable, > IntPtr lpTotalNumberOfBytes, > IntPtr lpTotalNumberOfFreeBytes > ); > "@ -passthru -name MyGetDiskFreeSpaceEx > # Alloc some memory ... > $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); > $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); > $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); > # Call 'GetDiskFreeSpaceEx' ... > $a::GetDiskFreeSpaceEx("\\.host\Shared Folders\files", $fba, $tnb, > $nfb) > # Get the Value storing in the memory pointed by $fba... > $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) > $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) > $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) > # Display the result ... > "FreeBytesAvailable: $($x)" > "TotalNumberOfBytes: $($y)" > "TotalNumberOfFreeBytes: $($z)" > # !! Free the memory ASAP.... > [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); > [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); > [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); > > I know this is really painful...But I just Call a Win32 API in > PowerShell. And I have to say PowerShell is really really really > Powerfullllllll............ > > Tao Ma > > "David Kriz" <david.kriz@ccv.cz> > 写入消息新闻:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.g bl... > >> 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. >> |
|
|
|
#18 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi Shay,
If I don't map the 'shared folder' on my computer, I cannot retrieve the freespace. The 'GetDiskSpaceEx' can retrieve it without mapping. That's why I call a Win32 API in PowerShell. Tao Ma "Shay Levi" <no@addre.ss> ??????:89228ed22eec08ca93b39c29dfb8@news.microsoft .com... > > Hi Mao > > You can try this, it's a PowerShell cross-version code: > > [io.driveinfo]::getdrives() > > and based on the result, get the free space for fixed drives: > > [io.driveinfo]::getdrives() | where {$_.DriveType -eq "Fixed"} | select > Name,AvailableFreeSpace > > > There's is also the wmi option: > > gwmi Win32_LogicalDisk | where {$_.DriveType -eq 3} | select > deviceID,FreeSpace > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > >> Hi David, >> >> I just write a painful code to query shared folder free space. Please >> do not mind my poor English. I'm not a native Speaker. >> >> Firstly, I tried to use System.IO.DriveInfo to solve this problem. But >> I realize that it doesn't accept UNC format as its parameter. >> >> Then I noticed that GetDiskFreeSpace can be used here. I don't know >> how to call a win32 api in PowerShell at all yesterday... >> >> There is post on the PowerShell Team Blog which introduce >> "Show-PowerShell / >> Hide-PowerShell". After I read it, I know I can call >> GetDiskFreeSpace in PowerShell.... >> # Just declare Win32 API... >> $a = Add-Type -memberDefinition @" >> [DllImport("Kernel32.dll")] >> public static extern bool GetDiskFreeSpaceEx( >> string lpDirectoryName, >> IntPtr lpFreeBytesAvailable, >> IntPtr lpTotalNumberOfBytes, >> IntPtr lpTotalNumberOfFreeBytes >> ); >> "@ -passthru -name MyGetDiskFreeSpaceEx >> # Alloc some memory ... >> $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >> $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >> $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >> # Call 'GetDiskFreeSpaceEx' ... >> $a::GetDiskFreeSpaceEx("\\.host\Shared Folders\files", $fba, $tnb, >> $nfb) >> # Get the Value storing in the memory pointed by $fba... >> $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) >> $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) >> $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) >> # Display the result ... >> "FreeBytesAvailable: $($x)" >> "TotalNumberOfBytes: $($y)" >> "TotalNumberOfFreeBytes: $($z)" >> # !! Free the memory ASAP.... >> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); >> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); >> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); >> >> I know this is really painful...But I just Call a Win32 API in >> PowerShell. And I have to say PowerShell is really really really >> Powerfullllllll............ >> >> Tao Ma >> >> "David Kriz" <david.kriz@ccv.cz> >> 写入消息新闻:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.g bl... >> >>> 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. >>> > > |
|
|
|
#19 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi Tao, Sorry for misspelling your name please ignore my last post, it doesn'trelate to shares. --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com > Hi Shay, > > If I don't map the 'shared folder' on my computer, I cannot retrieve > the freespace. > > The 'GetDiskSpaceEx' can retrieve it without mapping. > > That's why I call a Win32 API in PowerShell. > > Tao Ma > > "Shay Levi" <no@addre.ss> > ??????:89228ed22eec08ca93b39c29dfb8@news.microsoft .com... > >> Hi Mao >> >> You can try this, it's a PowerShell cross-version code: >> >> [io.driveinfo]::getdrives() >> >> and based on the result, get the free space for fixed drives: >> >> [io.driveinfo]::getdrives() | where {$_.DriveType -eq "Fixed"} | >> select Name,AvailableFreeSpace >> >> There's is also the wmi option: >> >> gwmi Win32_LogicalDisk | where {$_.DriveType -eq 3} | select >> deviceID,FreeSpace >> >> --- >> Shay Levi >> $cript Fanatic >> http://scriptolog.blogspot.com >>> Hi David, >>> >>> I just write a painful code to query shared folder free space. >>> Please do not mind my poor English. I'm not a native Speaker. >>> >>> Firstly, I tried to use System.IO.DriveInfo to solve this problem. >>> But I realize that it doesn't accept UNC format as its parameter. >>> >>> Then I noticed that GetDiskFreeSpace can be used here. I don't know >>> how to call a win32 api in PowerShell at all yesterday... >>> >>> There is post on the PowerShell Team Blog which introduce >>> "Show-PowerShell / >>> Hide-PowerShell". After I read it, I know I can call >>> GetDiskFreeSpace in PowerShell.... >>> # Just declare Win32 API... >>> $a = Add-Type -memberDefinition @" >>> [DllImport("Kernel32.dll")] >>> public static extern bool GetDiskFreeSpaceEx( >>> string lpDirectoryName, >>> IntPtr lpFreeBytesAvailable, >>> IntPtr lpTotalNumberOfBytes, >>> IntPtr lpTotalNumberOfFreeBytes >>> ); >>> "@ -passthru -name MyGetDiskFreeSpaceEx >>> # Alloc some memory ... >>> $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>> $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>> $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>> # Call 'GetDiskFreeSpaceEx' ... >>> $a::GetDiskFreeSpaceEx("\\.host\Shared Folders\files", $fba, $tnb, >>> $nfb) >>> # Get the Value storing in the memory pointed by $fba... >>> $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) >>> $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) >>> $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) >>> # Display the result ... >>> "FreeBytesAvailable: $($x)" >>> "TotalNumberOfBytes: $($y)" >>> "TotalNumberOfFreeBytes: $($z)" >>> # !! Free the memory ASAP.... >>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); >>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); >>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); >>> I know this is really painful...But I just Call a Win32 API in >>> PowerShell. And I have to say PowerShell is really really really >>> Powerfullllllll............ >>> >>> Tao Ma >>> >>> "David Kriz" <david.kriz@ccv.cz> >>> 写入消息新闻:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.g bl... >>>> 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. >>>> |
|
|
|
#20 |
|
Guest
Posts: n/a
|
Re: Query shared folder free space
Hi Shay,
It's ok.. My teacher dit it ten years ago...lol David uses dir \\bck01\backups in the original thread. So I try to get the freespace without mapping it. I can do it in cmd.exe but not in the PowerShell. That's why I write such painful codes... Tao Ma "Shay Levi" <no@addre.ss> ??????:89228ed22eece8ca93b813e958c2@news.microsoft .com... > > Hi Tao, > > Sorry for misspelling your name please ignore my last post, it doesn't> relate to shares. > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > >> Hi Shay, >> >> If I don't map the 'shared folder' on my computer, I cannot retrieve >> the freespace. >> >> The 'GetDiskSpaceEx' can retrieve it without mapping. >> >> That's why I call a Win32 API in PowerShell. >> >> Tao Ma >> >> "Shay Levi" <no@addre.ss> >> ??????:89228ed22eec08ca93b39c29dfb8@news.microsoft .com... >> >>> Hi Mao >>> >>> You can try this, it's a PowerShell cross-version code: >>> >>> [io.driveinfo]::getdrives() >>> >>> and based on the result, get the free space for fixed drives: >>> >>> [io.driveinfo]::getdrives() | where {$_.DriveType -eq "Fixed"} | >>> select Name,AvailableFreeSpace >>> >>> There's is also the wmi option: >>> >>> gwmi Win32_LogicalDisk | where {$_.DriveType -eq 3} | select >>> deviceID,FreeSpace >>> >>> --- >>> Shay Levi >>> $cript Fanatic >>> http://scriptolog.blogspot.com >>>> Hi David, >>>> >>>> I just write a painful code to query shared folder free space. >>>> Please do not mind my poor English. I'm not a native Speaker. >>>> >>>> Firstly, I tried to use System.IO.DriveInfo to solve this problem. >>>> But I realize that it doesn't accept UNC format as its parameter. >>>> >>>> Then I noticed that GetDiskFreeSpace can be used here. I don't know >>>> how to call a win32 api in PowerShell at all yesterday... >>>> >>>> There is post on the PowerShell Team Blog which introduce >>>> "Show-PowerShell / >>>> Hide-PowerShell". After I read it, I know I can call >>>> GetDiskFreeSpace in PowerShell.... >>>> # Just declare Win32 API... >>>> $a = Add-Type -memberDefinition @" >>>> [DllImport("Kernel32.dll")] >>>> public static extern bool GetDiskFreeSpaceEx( >>>> string lpDirectoryName, >>>> IntPtr lpFreeBytesAvailable, >>>> IntPtr lpTotalNumberOfBytes, >>>> IntPtr lpTotalNumberOfFreeBytes >>>> ); >>>> "@ -passthru -name MyGetDiskFreeSpaceEx >>>> # Alloc some memory ... >>>> $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>>> $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>>> $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); >>>> # Call 'GetDiskFreeSpaceEx' ... >>>> $a::GetDiskFreeSpaceEx("\\.host\Shared Folders\files", $fba, $tnb, >>>> $nfb) >>>> # Get the Value storing in the memory pointed by $fba... >>>> $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) >>>> $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) >>>> $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) >>>> # Display the result ... >>>> "FreeBytesAvailable: $($x)" >>>> "TotalNumberOfBytes: $($y)" >>>> "TotalNumberOfFreeBytes: $($z)" >>>> # !! Free the memory ASAP.... >>>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); >>>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); >>>> [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); >>>> I know this is really painful...But I just Call a Win32 API in >>>> PowerShell. And I have to say PowerShell is really really really >>>> Powerfullllllll............ >>>> >>>> Tao Ma >>>> >>>> "David Kriz" <david.kriz@ccv.cz> >>>> 写入消息新闻:%23oNghD1wIHA.4376@TK2MSFTNGP06.phx.g bl... >>>>> 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. >>>>> > > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |