If I RDP to my Windows 2016 server (called LAUREL) and run this powershell, it works fine:
Clear-RecycleBin -DriveLetter C -force
However if I run from my Windows 10 workstation logged on as a Domain Admin, the command:
icm -ComputerName laurel -ScriptBlock {Clear-RecycleBin -DriveLetter C -force}
I get:
The system cannot find the path specified
At line:1 char:1
+ icm -ComputerName laurel -ScriptBlock {Clear-RecycleBin -DriveLetter ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (RecycleBin:String) [Clear-RecycleBin], Win32Exception
+ FullyQualifiedErrorId : FailedToClearRecycleBin,Microsoft.PowerShell.Commands.ClearRecycleBinCommand
+ PSComputerName : laurel
Any ideas on how to clear a recycle bin on a remote server? This snippet of powershell will be integrated into an automated VM build.