Get-ChildItem -LiteralPath $Path -Directory -Recurse -ErrorVariable errvar | Select-Object -ExpandProperty FullName

Use case: Trying to get all the folders in the D folder with folder size and there are folders whose name is very long resulting in the below error. Using Powershell version of 5.0 and tried literal path still error remains the same.
Error:
The specified path, file name, or both are too long. The fully qualified file name must
be less than 260 characters, and the directory name must be less than 248 charac
ters.

Brindha,
Welcome to the forum. :wave:t3:

Have you enabled the Long Path Support?

@Olaf, Thanks. We will be taking the directory size of remote servers where we don’t have access to enable long paths or change any existing values in HKLM

Then you might talk to the responsible people about. :man_shrugging:t3:

Without enabling the long path is there any workaround.

Nothing I know of. :man_shrugging:t3:

ok. Thanks for the info.

Take a look at this:

.net - How can I get PowerShell’s Get-ChildItem command to list files in a path longer than 260 characters? - Stack Overflow

TLDR; there’s a workaround that someone mentions that doesn’t seem to require enabling long path support.

Not confident it will work but might be worth giving a shot as it seems pretty easy to add.