Dismount USB External Drive using powershell
Posted
by JC
on Server Fault
See other posts from Server Fault
or by JC
Published on 2010-04-09T11:15:18Z
Indexed on
2010/04/09
11:23 UTC
Read the original article
Hit count: 546
Hello,
I am attempting to dismount an external USB drive using powershell and I cannot successfuly do this. The following script is what I use:
#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)
I then check my computer to check if drive is unmounted but it is now.
The boolean parameters $force and $permanent have been tried with different permutations to no avail. The exit code returned by the dismount command changes when the params are toggled.
(0,0) = exit code 0
(0,1) = exit code 2
(1,0) = exit code 0
(1,1) = exit code 2
The documentation for exit code 2 indicates that there are existing mount points as a reason why it cannot dismount. Although I am trying to dismount the only mount point that exists so I am unsure what this exit code is trying to tell me.
Having already trawled the web for people experiencing similar problems I have only found one additional command to try and that is the following:
# executed after the .Dismount() command
$drive.Put()
This additional command does not help.
I am running out of things to try, so any assistance anyone can give me would be greatly appreciated,
Thanks.
© Server Fault or respective owner