I'm trying to remove everyone's Chrome cache directory with the following script but it keeps failing on this ridiculous error that makes no sense at all.
method invocation failed because system.io.directoryinfo does not contain a method named op_addition
Even when I just write the $loc to the console window I get the error. What am I doing wrong here?
$path = Get-ChildItem C:\Users\*\ | ?{ $_.PSIsContainer }
ForEach ($folder in $path) {
$loc = $folder + "\AppData\Local\Google\Chrome\User Data\Default\Cache"
# Remove-Item $loc
Write-Host $loc
}
Because what you are trying to do is concatenate 2 string, but $folder
is not a string. It's a system.io.directoryinfo
object, do something like this instead:
$loc = $folder.FullName + "\AppData\Local\Google\Chrome\User Data\Default\Cache"
$Folder.Fullname returns a string and that can be concatenated.