在Windows上,如果回收站损坏,Windows GUI中将显示类似下图的提示:

我想使用PowerShell自动检查这个问题。如何检查挂载点(无论是目录挂载还是盘符驱动器)下的回收站是否损坏?我在PowerShell中找到的唯一与回收站相关的cmdlet是Clear-RecycleBin。我还研究了如何在C#中执行此操作,只找到了通过P/Invoke访问Win32应用程序接口来清除回收站的方法,但没有介绍如何以编程方式检查回收站的完整性。
发布于 2020-01-29 23:53:09
也许这样的东西对你有用:
$bin = 'C:\$Recycle.Bin'
try {
$items = Get-ChildItem -Path $bin -Force -ErrorAction Stop
Write-Host "$bin seems just fine. Contains $($items.Count) items." -ForegroundColor Green
}
catch {
Write-Host "$bin looks corrupted.." -ForegroundColor Red
}https://stackoverflow.com/questions/59968356
复制相似问题