繁体   English   中英

使用 PowerShell 检查回收站是否损坏

[英]Check if Recycle Bin is corrupted with PowerShell

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

回收站损坏错误

我想使用 PowerShell 自动对此进行检查。 如何检查挂载点(无论是目录挂载还是盘符驱动器)下的回收站是否损坏? 我在 PowerShell 中找到的唯一与回收站相关的 cmdlet 是Clear-RecycleBin 我还研究了如何从 C# 执行此操作,并且只找到了P/InvokeWin32 API 以清除回收站的方法,但没有关于如何以编程方式检查回收站的完整性。

也许这样的事情对你有用:

$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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM