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 - Optimizing PS Script to List directories

Reply
 
Old 06-20-2007   #1 (permalink)
spdr


 
 

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 SpecsSystem Spec
Old 06-21-2007   #2 (permalink)
Jeff


 
 

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 SpecsSystem Spec
Old 06-21-2007   #3 (permalink)
Roman Kuzmin


 
 

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 SpecsSystem Spec
Old 06-21-2007   #4 (permalink)
Roman Kuzmin


 
 

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 SpecsSystem Spec
Old 06-24-2007   #5 (permalink)
Jacques Barathon [MS]


 
 

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 SpecsSystem Spec
Old 06-24-2007   #6 (permalink)
spdr


 
 

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 SpecsSystem Spec
Reply

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


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