Trying to maintain a routine that uses Powershell Get-ChildItem to scan Windows directories, and lists the contents.
Since Powershell represents the next generation console accompanying Windows, you'd think file system traversal would be ironclad (the most fundamental computer function), but there have been several complications.
Symbolic links looping itemization was one issue (resolved by excluding -Attribute !ReparsePoints)
Another pesky issue has been very long file paths. For whatever reason, some Powershell configurations cannot list files when the path exceeds a certain character length.
Workarounds explored:
Using -LiteralPath instead of -Path, and placing
\\?\
or\\?\UNC\
prefixes in the path Handling Path Too Long Exception with New-PSDriveMapping a portion of the longer path to a lettered PS-Drive to get in under the character limit (the lettered drive "workaround" allowed get-childItem commands to execute, but produced the same "path too long" error.
Installing Powershell 6 (CORE) in hopes that it somehow cured Powershell 5.1
To my surprise, I tested the routine on my desktop and it has no problem with the long paths, no special handlings was necessary at all. (longest path was 300 characters)
However, when I run the same on a Windows Server 2012 (virtual machine), it is still balking on the long paths.
Both machines are now running Powershell 5.1, here are the $PSVersionTable
DESKTOP Win7 INSTANCE (works without issue)
Name Value
---- ----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0,4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
SERVER 2012 INSTANCE (cannot handle long paths)
Name Value
---- -----
PSVersion 5.1.14409.1005
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1005
CLRVersion 4.0.30319.36460
Any ideas how I can get the SERVER 2012 INSTANCE functional? I see that the build numbers for Powershell 5.1 are different, not sure how to align the builds identically, and do you think that is the root cause?
One other strange thing the 2012 Server is doing, is Powershell by default is not picking up mapped network drives from windows explorer. So if I map drive 'X:' to some other network location, the 2012 Server cannot by default see it in Powershell, and needs to have a PS-Drive mounted manually before it can "replicate" the mapped drive already in use by Windows Explorer.
Appreciate your help on this, just trying to keep track of some files! :D