Skip to content

Instantly share code, notes, and snippets.

@giseongeom
Last active January 23, 2018 13:05
Show Gist options
  • Select an option

  • Save giseongeom/471118ea984dab5461b3f145c62374b3 to your computer and use it in GitHub Desktop.

Select an option

Save giseongeom/471118ea984dab5461b3f145c62374b3 to your computer and use it in GitHub Desktop.
Eject-USB
function MyEject-USB {
# See https://blogs.technet.microsoft.com/heyscriptingguy/2011/01/11/validate-powershell-parameters-before-running-the-script/
param
(
[Parameter(Mandatory = $true)]
[ValidatePattern("^[A-Za-z]$")]
$Drive
)
# See https://superuser.com/questions/1283149/remove-usb-device-from-commandline
(New-Object -comObject Shell.Application).NameSpace(17).ParseName("$Drive`:").InvokeVerb('Eject')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment