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?
get-childitem is going after other directories
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.
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.
Re: get-childitem is going after other directories
Yes. This is what the "-recurse" parameter does. Remove it to not behave this way.localpct wrote: Why is it searching other directories? Is this normal?
Re: get-childitem is going after other directories
Gotcha. Thanks. This has sped up the process immensely.jvierra wrote:Yes. This is what the "-recurse" parameter does. Remove it to not behave this way.localpct wrote: Why is it searching other directories? Is this normal?