PowerShell安全删除U盘 7


function Eject-FlashDrive
{
    Write-Host "请选择要删除的U盘:"
    foreach ($device in (Get-WmiObject -Class Win32_LogicalDisk –filter "DriveType=2") | Out-GridView -PassThru )
    {
        $sa = new-object -com Shell.Application
        $sa.Namespace(17).items() | 
        ForEach {
            If ($_.Name -match $device.$DeviceID ) 
            {
                $_.InvokeVerb("Eject")
            }
           } 
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($sa) 
        Remove-Variable sa
    }    
}
本文链接: https://www.pstips.net/eject-u-drive.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

7 条评论 “PowerShell安全删除U盘