PowerShell: Eject Disk
eject disk on wisdows using PowerShell
https://serverfault.com/questions/130887/dismount-usb-external-drive-using-powershell
$vol = get-wmiobject -Class Win32_Volume | where{$_.Name -eq 'F:\'} $vol.DriveLetter = $null $vol.Put() $vol.Dismount($false, $false) # ssss--------------------------------------------------- #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) # ssss--------------------------------------------------- # Retrieved from http://sushihangover.blogspot.nl/2012/02/powershell-eject-local-or-remote.html
(New-Object -ComObject Shell.Application).Namespace(17).ParseName("E:").InvokeVerb("Eject")
Create a COM object to manage Windows desktop
New-Object -COMObject "Shell.Application" | Get-Member
TypeName: System.__ComObject#{286e6f1b-7113-4355-9562-96b7e9d64c54} Name MemberType Definition ---- ---------- ---------- AddToRecent Method void AddToRecent (Variant varFile, string bstrCategory) BrowseForFolder Method Folder BrowseForFolder (int Hwnd, string Title, int Options, Variant RootFolder) CanStartStopService Method Variant CanStartStopService (string ServiceName) CascadeWindows Method void CascadeWindows () ControlPanelItem Method void ControlPanelItem (string bstrDir) EjectPC Method void EjectPC () Explore Method void Explore (Variant vDir) ExplorerPolicy Method Variant ExplorerPolicy (string bstrPolicyName) FileRun Method void FileRun () FindComputer Method void FindComputer () FindFiles Method void FindFiles () FindPrinter Method void FindPrinter (string Name, string location, string model) GetSetting Method bool GetSetting (int lSetting) GetSystemInformation Method Variant GetSystemInformation (string Name) Help Method void Help () IsRestricted Method int IsRestricted (string Group, string Restriction) IsServiceRunning Method Variant IsServiceRunning (string ServiceName) MinimizeAll Method void MinimizeAll () NameSpace Method Folder NameSpace (Variant vDir) Open Method void Open (Variant vDir) RefreshMenu Method void RefreshMenu () SearchCommand Method void SearchCommand () ServiceStart Method Variant ServiceStart (string ServiceName, Variant Persistent) ServiceStop Method Variant ServiceStop (string ServiceName, Variant Persistent) SetTime Method void SetTime () ShellExecute Method void ShellExecute (string File, Variant vArgs, Variant vDir, Variant vOperation, Varia ShowBrowserBar Method Variant ShowBrowserBar (string bstrClsid, Variant bShow) ShutdownWindows Method void ShutdownWindows () Suspend Method void Suspend () TileHorizontally Method void TileHorizontally () TileVertically Method void TileVertically () ToggleDesktop Method void ToggleDesktop () TrayProperties Method void TrayProperties () UndoMinimizeALL Method void UndoMinimizeALL () Windows Method IDispatch Windows () WindowsSecurity Method void WindowsSecurity () WindowSwitcher Method void WindowSwitcher () Application Property IDispatch Application () {get} Parent Property IDispatch Parent () {get}
(New-Object -COMObject "Shell.Application") .ToggleDesktop()