Page 1 of 1

get-childitem is going after other directories

Posted: Fri Jan 22, 2016 6:15 pm
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?

Re: get-childitem is going after other directories

Posted: Fri Jan 22, 2016 7:19 pm
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.

Re: get-childitem is going after other directories

Posted: Tue Jan 26, 2016 1:42 pm
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.

Re: get-childitem is going after other directories

Posted: Tue Jan 26, 2016 1:44 pm
by jvierra
You are welcome and good luck.