I have been playing with this part of a script I am writing and I am stuck in a bottle neck.
I am working on getting a list of permissions on shared folders. This is roughly where I started:
Get-ChildItem "\\$FileServer\$share" -Directory -Recurse | select -ExpandProperty FullName -OutVariable DirectoryPaths |out-null
I found that this works, but on a file server holding a large number of shares get-childitem is very slow. So I changed my code to use:
$DirectoryPaths = [System.IO.Directory]::EnumerateDirectories("\\$FileServer\$share", '*.*', 'AllDirectories')
The above line is way faster. The issue is working with the variable $DirectoryPaths.
The variable $DirectoryPaths is now the following type.
IsPublic IsSerial Name BaseType
A bit of a definition a long time is days not just a few more seconds. If someone has a better idea of a way to get this directory listing or somehow deal with the variable type I would be very grateful.
You're dealing with a scripting language; loops are always a bottleneck, especially when you're dealing with zillions of objects. A better approach, if possible, would be to push the script via Invoke-Command and let it run on the remote machine rather than over SMB. But, zillions of objects is still zillions of objects. PowerShell just isn't optimized for max speed in that scenario.
You must be logged in to reply to this topic.