get-childitem is going after other directories

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

get-childitem is going after other directories

Post by localpct »

I have a script that goes out and deletes folders left over from installations

INVOKE-COMMAND -COMPUTERNAME $computer -SCRIPTBLOCK { GET-CHILDITEM -PATH C:\SWSetup -recurse | WHERE-OBJECT { $_.PSISCONTAINER -AND (GET-CHILDITEM -PATH $_.FULLNAME -recurse | WHERE-OBJECT { !$_.PSISCONTAINER }) -EQ $NULL } | REMOVE-ITEM -FORCE -RECURSE }

But, a lot of the times it hangs and I just ran it through ISE and I'm getting this


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 characters.
+ CategoryInfo : ReadError: (C:\Program File...sut\diagnostics:String) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : computername

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 characters.
+ CategoryInfo : ReadError: (C:\Program File...sut\diagnostics:String) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : computername

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 characters.
+ CategoryInfo : ReadError: (C:\Windows\CSC\...0145efa6b30.swf:String) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : computername

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 characters.
+ CategoryInfo : ReadError: (C:\Windows\CSC\...nd Calculations:String) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : computername

Why is it searching other directories? Is this normal?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem is going after other directories

Post by jvierra »

localpct wrote: Why is it searching other directories? Is this normal?
Yes. This is what the "-recurse" parameter does. Remove it to not behave this way.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: get-childitem is going after other directories

Post by localpct »

jvierra wrote:
localpct wrote: Why is it searching other directories? Is this normal?
Yes. This is what the "-recurse" parameter does. Remove it to not behave this way.
Gotcha. Thanks. This has sped up the process immensely.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem is going after other directories

Post by jvierra »

You are welcome and good luck.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked