Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Dismount drive

Reply
 
Old 05-13-2008   #1 (permalink)
CodeTestDummy


 
 

Dismount drive

Why is not working? It works in the VBS.

$colDrives = get-wmiobject -Class Win32_Volume -namespace
"root\CIMV2" -computername $strComputer | where{$_.name -eq $strDrive}

foreach($objItem in $colDrives)
{
$objItem.Dismount($True, $True)

}


My System SpecsSystem Spec
Old 05-13-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Dismount drive

CodeTestDummy wrote:
Quote:

> Why is not working? It works in the VBS.
>
> $colDrives = get-wmiobject -Class Win32_Volume -namespace "root\CIMV2"
> -computername $strComputer | where{$_.name -eq $strDrive}
>
> foreach($objItem in $colDrives)
> {
> $objItem.Dismount($True, $True)
>
> }
Because you're dealing with remote objects, I'm thinking you might have
to add this line:

....
$objItem.Dismount($true,$true)
$objItem.Put() <--Add this
....

**Not tested**

Marco
My System SpecsSystem Spec
Old 05-13-2008   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: Dismount drive

I'm not able to make this work in either PowerShell or VBScript. It appears
to work if executed, but the invocation always returns a result code of 2,
which means that the volume has mount points. Below is my test VBScript
code. It appears that the mount point has to be removed before the volume
can be dismounted.

If I change the second parameter to false, the dismount succeeds - not that
I can tell what that means, since it is still visible in Explorer. However,
the returned result code is a 0. Possibly this is because I'm using a drive
letter assigned USB drive to test this against. This is also a local test as
you can tell, so it doesn't precisely mimic what you did.

Here's the PowerShell version, working against drive K:

get-wmiobject -Class Win32_Volume | where{$_.name -eq 'K:\'} |
%{$_.Dismount($true,$false)}

Here's the VBScript version:


Set volumes = GetObject("winmgmts://./root/cimv2")._
ExecQuery("Select * from Win32_Volume")

For Each volume in volumes

if volume.Name = "K:\" Then
result = volume.Dismount(true, false)
WScript.Echo result
end if
next


"CodeTestDummy" <sharp_mind.TAKETHISOUT@xxxxxx> wrote in
message news:E66E0B26-83D1-4620-AF32-AB3AAF0FD1FC@xxxxxx
Quote:

> Why is not working? It works in the VBS.
>
> $colDrives = get-wmiobject -Class Win32_Volume -namespace
> "root\CIMV2" -computername $strComputer | where{$_.name -eq $strDrive}
>
> foreach($objItem in $colDrives)
> {
> $objItem.Dismount($True, $True)
>
> }
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Combo RAID1 and standard Drive setup problem - Unallocated Drive General Discussion
Mount or Dismount a Drive or Partition to a Folder Tutorials
Access XP data drive using Vista Ult (XP drive=slave drive only NO Vista account administration
Vista on the C: drive but System drive is the D: drive - any way to Vista installation & setup
Vista maping drive to server 2000 shared drive not recognize user/ Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46