<\/div>\n<\/aside>\n","upvoteCount":0,"datePublished":"2021-08-06T14:19:34.000Z","url":"https://community.spiceworks.com/t/get-childitem-long-path-issue/807710/9","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
you can try to use robocopy to list the filenames.<\/p>","upvoteCount":0,"datePublished":"2021-08-06T14:20:58.000Z","url":"https://community.spiceworks.com/t/get-childitem-long-path-issue/807710/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
I was recently working on a similar problem; have users having trouble editing data because their paths are like short books.<\/p>\n
Did you not have quotes around your path?<\/p>\n
So, to find those PATH TOO LONG attributes:<\/p>\n
$root = '\\\\UNC\\?\\Server\\Share'\n$folders = gci -LiteralPath $root -directory -recurse -force -ea SilentlyContinue -ev ERR | where {whatever you need} | select -exp FullName\n\n<\/code><\/pre>\nYou likely don’t need the where clause; I did. \nNotice the SINGLE QUOTES around the path to the value for $root. \nI did a bunch of stuff with folders which isn’t relevant to your issue. \nHowever:<\/p>\n
if($err) {\n foreach ($e in $err) {\n $fName = $e.TargetObject\n $eExc = $e.Exception\n if($eExc -match \"Could not find part of the path\") {\n $len = $fName.Length\n write-host \"PATH TOO LONG for $fname with $len\"\n }\n }\n}\n<\/code><\/pre>\nEven better, write this out to a log and send it to the folks creating their own nightmares. \nYW!<\/p>","upvoteCount":0,"datePublished":"2021-08-06T17:33:54.000Z","url":"https://community.spiceworks.com/t/get-childitem-long-path-issue/807710/11","author":{"@type":"Person","name":"gary-m-g","url":"https://community.spiceworks.com/u/gary-m-g"}},{"@type":"Answer","text":"
Sorry for the delay in replying.<\/p>\n
Though I am sure that any of these would work for me I have found that just by making sure Long Paths was enabled in the registry on a Server 2019 box I am able to get the information I need as this is supported natively in that OS.<\/p>\n
Thanks for all the replies!<\/p>","upvoteCount":0,"datePublished":"2021-09-09T12:45:42.000Z","url":"https://community.spiceworks.com/t/get-childitem-long-path-issue/807710/12","author":{"@type":"Person","name":"briankeller","url":"https://community.spiceworks.com/u/briankeller"}}]}}
I am trying to return a list of files from a share with specific properties. The problem is with the character limitation for the path. I have looked at many articles and tried several things to get this to work but to no avail.
Recently I have updated powershell on the system that I need to run this on with 5.1. As I understand, the following snipit should work however I am getting an invalid character error when I try to run it. Any help appreciated.
Thank you
Get-ChildItem -LiteralPath \\?\UNC\Server\share$ -File -Recurse -Attributes sparse+offline | select fullname | Export-Csv D:\temp\DeptIT.csv -NoTypeInformation
3 Spice ups
Evan7191
(Evan7191)
August 6, 2021, 11:44am
2
Please post the full error that you are getting.
Get-ChildItem : Illegal characters in path.
At line:1 char:1
Get-ChildItem -LiteralPath \?\UNC\server\share$\IT -File -Recurse …
CategoryInfo : NotSpecified: ( [Get-ChildItem], ArgumentException
FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand
Evan7191
(Evan7191)
August 6, 2021, 1:11pm
4
Is the question mark actually in the path? Do you get an error with this?
Get-ChildItem -Path \\Server\share$ -File -Recurse -Attributes sparse+offline | select fullname | Export-Csv D:\temp\DeptIT.csv -NoTypeInformation
Am just going to ask the question @techadmin8 is trying to avoid in a round about polite way. .
Is the part edited for the post here " \?\UNC\server\share$\IT" or this actually in the script ?
Yes that is edited for the post.
Yes the ? is in the command. That is apparently part of the command for long paths. If you are looking to get information locally say, the command is \?\C:\whatever. At least that is what I am getting from articles online. That should bypass the 246 character limit when used with -LiteralPath.
I do not get an error running without \?\UNC but I get long path errors trying to retrieve files.
Neally
(Neally)
August 6, 2021, 2:19pm
9
Neally
(Neally)
August 6, 2021, 2:20pm
10
you can try to use robocopy to list the filenames.
gary-m-g
(Gary M G)
August 6, 2021, 5:33pm
11
I was recently working on a similar problem; have users having trouble editing data because their paths are like short books.
Did you not have quotes around your path?
So, to find those PATH TOO LONG attributes:
$root = '\\UNC\?\Server\Share'
$folders = gci -LiteralPath $root -directory -recurse -force -ea SilentlyContinue -ev ERR | where {whatever you need} | select -exp FullName
You likely don’t need the where clause; I did.
Notice the SINGLE QUOTES around the path to the value for $root.
I did a bunch of stuff with folders which isn’t relevant to your issue.
However:
if($err) {
foreach ($e in $err) {
$fName = $e.TargetObject
$eExc = $e.Exception
if($eExc -match "Could not find part of the path") {
$len = $fName.Length
write-host "PATH TOO LONG for $fname with $len"
}
}
}
Even better, write this out to a log and send it to the folks creating their own nightmares.
YW!
Sorry for the delay in replying.
Though I am sure that any of these would work for me I have found that just by making sure Long Paths was enabled in the registry on a Server 2019 box I am able to get the information I need as this is supported natively in that OS.
Thanks for all the replies!