【问题标题】:Check if Recycle Bin is corrupted with PowerShell使用 PowerShell 检查回收站是否已损坏
【发布时间】:2020-01-29 13:41:17
【问题描述】:

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

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

【问题讨论】:

    标签: windows powershell recycle-bin


    【解决方案1】:

    也许这样的东西对你有用:

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

    【讨论】:

    • 不幸的是,这是我尝试的第一件事。 gci 不会返回回收站目录下的任何内容,也不会出错。
    猜你喜欢
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 2011-04-24
    • 2017-10-26
    相关资源
    最近更新 更多