0

I want to use set-disk to put a usb drive in offline or unmount state, but I can't. Why does 'set-disk -number 2 -isoffline $false' work but 'set-disk -number 2 -isoffline $true' does not? And when does it work?

If you don't mind, please tell me how to put removal media into unmount state by poweshell.

PS C:\WINDOWS\system32> set-disk -number 2 -isoffline $false
PS C:\WINDOWS\system32> get-partition -disknumber 2 | format-list


UniqueId             : ~~~
AccessPaths          : {W:\, \\?\Volume~~~
DiskNumber           : 2
DiskPath             : ~~~
DriveLetter          : W
Guid                 :
IsActive             : False
IsBoot               : False
IsHidden             :
IsOffline            : False
IsReadOnly           :
IsShadowCopy         :
IsDAX                :
IsSystem             : False
NoDefaultDriveLetter :
Offset               : 1048576
OperationalStatus    : Online
PartitionNumber      : 1
Size                 : 28.87 GB
Type                 : FAT32 XINT13

PS C:\WINDOWS\system32> set-disk -number 2 -isoffline $true
set-disk : Not Supported

Extended information:
Removable media cannot be set to offline.
~~~
7_tree
  • 17
  • 1
  • 2

1 Answers1

0

As answerd in https://serverfault.com/questions/130887/dismount-usb-external-drive-using-powershell (which already mentioned by @lit)

you can unmount a usb drive using the following method

# Assuming that you need to unmount a removable device with letter F:
$driveletter = 'F:'
$driveEject = New-Object -comObject Shell.Application
$driveEject.Namespace(17).ParseName($driveletter).InvokeVerb("Eject")

I tested it on my machine and its working fine.

Mahmoud Moawad
  • 697
  • 7
  • 14