I understand there is a 260 character limit for win32, but I am curious as to why my code is half working. See below.
$Age_of_Files = -30
$Path = \'\\\\
You can turn on long paths in Windows 10. There's a gpo. https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/
This is a limitation of the Win32 API (see also). There's a PowerShell Module that supposedly works around the issue (haven't used it myself, though).
A common workaround is to shorten the path by substing the longest accessible path to a drive letter
& subst X: C:\longest\parent\folder
working on drive X:
, then deleting the temporary drive afterwards:
& subst X: /d
For network paths use net use
to the same end:
& net use X: \\server\share\longest\parent\folder
...
& net use X: /d