0

I need to list recursively all files in a UNC path with a specific extension (.PST).

I have tried this:

Get-ChildItem -Path "\\DFS.LAN\users\*" -Recurse | ?{$_.Name -like "*.pst"} |
    Select FullName

Some errors appears (path too long), how can I deal with it?

Get-ChildItem : Impossible de trouver une partie du chemin d'accès
'\\DFS.LAN\users\User1\Documents\...'.
Au caractère Ligne:1 : 1
+ Get-ChildItem -Path "\\DFS.LAN\users\*" -Recurse | ?{$_.Name -li ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (\\DFS.LAN\users...:String) [Get-ChildItem], DirectoryNotFoundException
    + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

EDIT

After a little search, it is possible (with PowerShell 5.1) to avoid error with long path name like this:

Get-ChildItem -LiteralPath "\\?\UNC\DFS.LAN\users\*" -Recurse |
    ?{$_.Name -like "*.pst"} |
    Select FullName

Explanation Here

Example

Get-ChildItem -LiteralPath '\\?\C:\Very long path' -Recurse

For UNC path, this is slightly different, the prefix being \?\UNC\ instead of \

Get-ChildItem -LiteralPath '\\?\UNC\127.0.0.1\c$\Very long path\' -Recurse

Is it possible to inscrease the speed of this listing?

EDIT

Maybe using the -Filter parameter increase the speed of this task ...

Get-ChildItem -LiteralPath "\\?\UNC\DFS.LAN\users\*" -Filter "*.pst" -Recurse |
    Select FullName
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Yann F.
  • 91
  • 3
  • 14
  • Did your updated command do what you need, or do you still have a question? – Bill_Stewart Nov 05 '19 at 15:04
  • I think you nailed it with your latest edit. Maybe one little thing: you may want to do `Select-Object -ExpandProperty FullName` to retrieve the name as string or shorten the code using `(Get-ChildItem -LiteralPath "\\?\UNC\DFS.LAN\users\*" -Filter "*.pst" -Recurse).FullName` – Theo Nov 05 '19 at 19:39

0 Answers0