小编JB.*_*JB.的帖子

使用 powershell 卸载 USB 外置驱动器

我正在尝试使用 powershell 卸载外部 USB 驱动器,但无法成功执行此操作。以下脚本是我使用的:

#get the Win32Volume object representing the volume I wish to eject 

$drive = Get-WmiObject Win32_Volume -filter "DriveLetter = 'F:'"

#call dismount on that object there by ejecting drive

$drive.Dismount($Force , $Permanent)
Run Code Online (Sandbox Code Playgroud)

然后我检查我的计算机以检查驱动器是否已卸载,但事实并非如此。

布尔参数 $force 和 $permanent 已尝试使用不同的排列,但无济于事。当参数被切换时,卸载命令返回的退出代码会发生变化。

(0,0) = exit code 0

(0,1) = exit code 2

(1,0) = exit code 0

(1,1) = exit code 2
Run Code Online (Sandbox Code Playgroud)

退出代码 2 的文档表明存在安装点是它无法卸载的原因。虽然我试图卸载存在的唯一挂载点,但我不确定这个退出代码试图告诉我什么。

已经在网上搜索遇到类似问题的人后,我只找到了一个额外的命令可以尝试,如下所示:

# executed after the .Dismount() command

$drive.Put() 
Run Code Online (Sandbox Code Playgroud)

这个额外的命令没有帮助。

我没有什么可以尝试的了,所以任何人都可以给我任何帮助将不胜感激。

scripting windows powershell hard-drive usb

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

hard-drive ×1

powershell ×1

scripting ×1

usb ×1

windows ×1