Support Forums

get-childitem is going after other directories

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
User avatar
localpct
Posts: 121
Joined: Wed Sep 09, 2015 12:53 pm

get-childitem is going after other directories

Postby localpct » Fri Jan 22, 2016 6:15 pm

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?
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get-childitem is going after other directories

Postby jvierra » Fri Jan 22, 2016 7:19 pm

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: 121
Joined: Wed Sep 09, 2015 12:53 pm

Re: get-childitem is going after other directories

Postby localpct » Tue Jan 26, 2016 1:42 pm

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.
User avatar
jvierra
Posts: 10026
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get-childitem is going after other directories

Postby jvierra » Tue Jan 26, 2016 1:44 pm

You are welcome and good luck.

Return to “Windows PowerShell”

Who is online

Users browsing this forum: No registered users and 2 guests