![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Optimizing PS Script to List directories Hey, If I run the command below it will list all directories that have the word "Data" in the path, if I run it locally it's real quick and can find all the paths within seconds, but I need to run it on all our remote file servers and it is dog slow and was wondering if anyone knew anyway to optimise it? get-childitem \\server\e$ "Data" -recurse | Where-Object {$_.mode - match "d" } | Select-Object fullname I am assuming it is slow because the first path of the command searches the entire file system to find all folders AND files that match "Data", then it is piped into the second part where it is then restricted down to folders and then on the second part when it is then restricted down to only output the path. It tries to bring across way too much information across the WAN to have it filtered down on my machine. I need to extract about 10 - 15 paths on 102 remote files servers, if it takes hours to do each server it's not worth doing a script and I'll just have to find them manually. The path I am looking for is never going be deep down in the file structure, it should be three levels down from root, and I don't want files, just the folder path, like ... \\server\x$\BusinessUnitX\Folder1\Data \\server\x$\BusinessUnitY\Folder1\Data Anyone have any ideas? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Optimizing PS Script to List directories On Jun 21, 9:23 am, spdr <p...@iinet.net.au> wrote: > Hey, > > If I run the command below it will list all directories that have the > word "Data" in the path, if I run it locally it's real quick and can > find all the paths within seconds, but I need to run it on all our > remote file servers and it is dog slow and was wondering if anyone > knew anyway to optimise it? > > get-childitem \\server\e$ "Data" -recurse | Where-Object {$_.mode - > match "d" } | Select-Object fullname > > I am assuming it is slow because the first path of the command > searches the entire file system to find all folders AND files that > match "Data", then it is piped into the second part where it is then > restricted down to folders and then on the second part when it is then > restricted down to only output the path. It tries to bring across way > too much information across the WAN to have it filtered down on my > machine. > > I need to extract about 10 - 15 paths on 102 remote files servers, if > it takes hours to do each server it's not worth doing a script and > I'll just have to find them manually. The path I am looking for is > never going be deep down in the file structure, it should be three > levels down from root, and I don't want files, just the folder path, > like ... > > \\server\x$\BusinessUnitX\Folder1\Data > \\server\x$\BusinessUnitY\Folder1\Data > > Anyone have any ideas? > Thanks One quick idea. The PSIsContainer NoteProperty will certainly be faster than the - match operator: get-childitem \\server\e$ "Data" -recurse | Where-Object {$_.PSIsContainer} | Select-Object fullname Other than that, I don't know. Jeff |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Optimizing PS Script to List directories You may slightly change Get-File.ps1 at http://nightroman.spaces.live.com/bl...39FA!131.entry so that it returns directories and ignores files completely. Hope this helps. -- Thanks, Roman Kuzmin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Optimizing PS Script to List directories Here is the prototype. You may get rid of used Get-Drive or use it from http://nightroman.spaces.live.com/bl...39FA!131.entry ## ## Author : Roman Kuzmin ## Synopsis : Get all directories ## ## Returns System.IO.DirectoryInfo objects or full names. ## -Root: root directory(s); single \\ or // denotes all physical drives. ## -Name: return full names as strings. ## ## *) requires Get-Drive.ps1. ## *) access errors are silently ignored. ## *) hidden and system items are included. ## *) reparse points directories are excluded. ## param ( [string[]]$Root = '.', [switch]$Name ) function GetDirectories([System.IO.DirectoryInfo]$di) { # ignore errors trap {continue} # directories foreach($d in $di.GetDirectories()) { if (!($d.Attributes -band [System.IO.FileAttributes]::ReparsePoint)) { if ($Name) { $d.FullName } else { $d } GetDirectories $d } } } if ($Root.Count -eq 1 -and ($Root[0] -eq '\\' -or $Root[0] -eq '//')) { foreach($d in Get-Drive) { GetDirectories $d.RootDirectory } } else { foreach($d in $Root) { GetDirectories $d } } -- Thanks, Roman Kuzmin "Roman Kuzmin" <z@z.z> wrote in message news:e72Mjb%23sHHA.4236@TK2MSFTNGP05.phx.gbl... > You may slightly change Get-File.ps1 at > http://nightroman.spaces.live.com/bl...39FA!131.entry so > that it returns directories and ignores files completely. > > Hope this helps. > > -- > Thanks, > Roman Kuzmin > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Optimizing PS Script to List directories "spdr" <pear@iinet.net.au> wrote in message news:1182392599.525362.127170@e9g2000prf.googlegroups.com... .... > I need to extract about 10 - 15 paths on 102 remote files servers, if > it takes hours to do each server it's not worth doing a script and > I'll just have to find them manually. The path I am looking for is > never going be deep down in the file structure, it should be three > levels down from root, and I don't want files, just the folder path, > like ... > > \\server\x$\BusinessUnitX\Folder1\Data > \\server\x$\BusinessUnitY\Folder1\Data Roman's answer with GetDirectories() might just be what you need. I also wanted to highlight an interesting feature of PowerShell which is not very well known: PS> dir \\server\x$\BusinessUnit*\Folder*\Data\* .... will list all items in both BusinessUnitX\Folder1\Data and BusinessUnitY\Folder1\Data folders, plus BusinessUnitX\Folder2\Data if it exists, etc. Might help you target your search more easily. Jacques |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Optimizing PS Script to List directories Thanks for all your help guys, I'll have a play and see how I go. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| set auditing on directories with script? | VB Script | |||
| List only directories with numbers | VB Script | |||
| Need Help With Script To List and Delete Printers | VB Script | |||
| List FTP Directories | PowerShell | |||