简体   繁体   English

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

[英]Check if Recycle Bin is corrupted with PowerShell

On Windows, if the Recycle Bin is corrupted, a prompt similar to the image below is shown in the Windows GUI:在 Windows 上,如果回收站损坏,Windows GUI 中会显示类似于下图的提示:

回收站损坏错误

I'd like to automate a check for this using PowerShell.我想使用 PowerShell 自动对此进行检查。 How can I check if the recycle bin under a mountpoint (whether it's a directory mount or letter drive) is corrupted?如何检查挂载点(无论是目录挂载还是盘符驱动器)下的回收站是否损坏? The only cmdlet I've found in PowerShell relating to the recycle bin is Clear-RecycleBin .我在 PowerShell 中找到的唯一与回收站相关的 cmdlet 是Clear-RecycleBin I've also looked at how to perform this from C# and only found methods to P/Invoke to the Win32 API to clear the recycle bin, but nothing on how to check the recycle bin's integrity programmatically.我还研究了如何从 C# 执行此操作,并且只找到了P/InvokeWin32 API 以清除回收站的方法,但没有关于如何以编程方式检查回收站的完整性。

Perhaps something like this works for you:也许这样的事情对你有用:

$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