Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Dismount drive

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-13-2008   #1 (permalink)
CodeTestDummy
Guest


 

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]
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Access XP data drive using Vista Ult (XP drive=slave drive only NO John C (Go Packers!) Vista account administration 0 06-23-2008 02:38 PM
trouble moving files from local drive to network drive dwsdad Vista networking & sharing 0 02-25-2008 06:32 AM
Vista on the C: drive but System drive is the D: drive - any way to hinnc Vista installation & setup 4 11-15-2007 11:33 AM
Vista maping drive to server 2000 shared drive not recognize user/ Sam Vista networking & sharing 1 11-02-2007 08:18 PM
Vista hard drive error check destroys a FAT 16 drive? Help! Jon Vista hardware & devices 1 09-12-2007 05:19 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51