You can't reference .Fullname in the catch because "$ underscore" will be the error object.
Please use the Code Sample icon when posting code. The "101010" icon.
Try it like this. I highly recommend using -whatif on the Remove-Item when you are testing.
$Folders = Get-ChildItem 'C:\Users\*\AppData\Roaming\Temp*' -Recurse
""
"Folders contains {0} entries." -f $Folders.count
""
$csv = ForEach ($File in $folders) {
Try {
Remove-Item $File.FullName -ErrorAction Stop -whatif
[PSCustomObject]@{
Path = $File.FullName
Action = "Removed"
Error = ""
}
}
Catch {
[PSCustomObject]@{
Path = $File.FullName
Action = "NotRemoved"
Error = $_
}
}
}
$csv | Export-Csv C:\Temp\RR_Cleanup_Output.csv -NoTypeInformation