locked
Change CDROM drive letter based on objItem.DeviceID RRS feed

  • Question

  • Good start was in: http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/14/change-drive-letters-and-labels-via-a-simple-powershell-command.aspx
    but does not actually seem to work (Win 7 x64)

    Get-WmiObject Win32_CDROMDrive

    does not actually display much, but could just use it like:

    $drive = get-WmiObject win32_cdromdrive -filter "Caption = 'ELBY CLONEDRIVE SCSI CdRom Device'"

    but then the following one fails:

    PS C:\Windows\system32> Set-WmiInstance -inputobject $drive -Arguments @{Drive="U:"}
    Set-WmiInstance : Provider is not capable of the attempted operation
    At line:1 char:16
    + Set-WmiInstance <<<<  -inputobject $drive -Arguments @{Drive="U:"}
        + CategoryInfo          : InvalidOperation: (:) [Set-WmiInstance], ManagementException
        + FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance

    Anybody having any good idea how to get it going?

    Thanks

    Seb

    Sunday, August 3, 2014 9:37 PM

Answers

  • Oh, my God; I'll take this one. I think what everyone is after is getting you to think this through. If you can get the drive letter from Win32_CDROMDrive class, then you'll know enough to change the drive letter. Take a look at my example.

    $IShouldBeLessRude = Get-WmiObject -Class Win32_CDROMDrive -Filter "Caption = 'ELBY CLONEDRIVE SCSI CdRom Device'" | Select-Object -ExpandProperty Drive
    
    $AskingForHelpRequiresIamLevelHeaded = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = '$($IShouldBeLessRude)'"
    
    Set-WmiInstance -InputObject $AskingForHelpRequiresIamLevelHeaded -Arguments @{DriveLetter="U:"}

    • Proposed as answer by Mike Laughlin Monday, August 4, 2014 7:46 PM
    • Marked as answer by scerazy Monday, August 4, 2014 7:55 PM
    Monday, August 4, 2014 7:29 PM
  • Yes, please stop pointing to a class which can not be used in described situation (as it makes no sense)

    Either scripting with PS can do it or NOT?

    If it can then please help in useful manner.

    If it can't lets stop wasting time.

    I am by far NOT a scripting guy, hence asking for help

    sebus

    What we are pointing at is the method you need to do you task.  You need to learn enough about Windows and scripting to understand the answer.

    You can choose the cdromdrive you are interested in by filtering for something that you think will identify it.  If the caption is the identifier then use the caption.  What you are missing is that the caption is not usable on Win32_Volume.  There is only one thing that links them in this situation and that is drive letter.  SO take the drive letter from you chosen CD and use it to select the volume whose drive letter you wish to change.  Once you have the related volume you can change the drive letter.

    Reading the blog post would have explained that.

    I showed you how to return the drive letter of the CD.  I also showed you how to filter the volume to get that device.

    The following works exactly as expected on my system.

    Get-WmiObject win32_cdromdrive -filter "Caption = 'hp DVD-RAM SW820 SCSI CdRom Device'" |
         ForEach-Object{
              Get-WmiObject Win32_Volume -filter "DriveLetter='$($_.Drive)'"
         }
    

    For more background on how to use PowerShell and WMI start here: http://technet.microsoft.com/en-US/scriptcenter/cc950497.aspx

    It is a pretty easy short video that gets you started.

    Here are more tutorials and resources: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Monday, August 4, 2014 7:46 PM
    • Marked as answer by scerazy Monday, August 4, 2014 7:55 PM
    Monday, August 4, 2014 7:38 PM

All replies

  • Sunday, August 3, 2014 10:36 PM
  • Go back and reread the page both you and jrv have linked. If you use the proper class, as mentioned in the article (Win32_Volume), then you'll be able to change the drive letter. I've tested it, and it works.
    Edit: Typo
    Monday, August 4, 2014 4:32 AM
  • Well, that was the very page I STARTED ON!

    Somehow I do not see how to use Win32_Volume with -filter "Caption = 'ELBY CLONEDRIVE SCSI CdRom Device'"

    Win32_Volume does NOT return any useful (for me in this case) info

    Seb


    • Edited by scerazy Monday, August 4, 2014 7:15 AM
    Monday, August 4, 2014 7:12 AM
  • Please try to read the whole article.  It explains in detail how to locate and alter a drive by volume.  YOu cannot use CAption as it is class specific.  YOu must use DriveLetter.


    ¯\_(ツ)_/¯

    Monday, August 4, 2014 10:36 AM
  • But that is as good as NONE.

    I do not care what the drive letter is (I do not even know it)

    What I care is that the RESULTING drive letter for the DeviceID is exactly what I want!

    So difficult to understand?

    Seb

    Monday, August 4, 2014 2:38 PM
  • But that is as good as NONE.

    I do not care what the drive letter is (I do not even know it)

    What I care is that the RESULTING drive letter for the DeviceID is exactly what I want!

    So difficult to understand?

    Seb

    Calm down and go read the article again.

    You're using the wrong class.

    Start from the very beginning.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Monday, August 4, 2014 2:46 PM
  • I know - reading is such a challenge.  Why read when we have computers that can read for us.  Reading is clearly obsolete.  Soon even humans will be obsolete.

    Here is a clue which can be extrapolated from what you already know:

    gwmi win32_cdromdrive | select Drive


    ¯\_(ツ)_/¯

    Monday, August 4, 2014 2:53 PM
  • To be fair we should also note that you will need to use this for your filter:

    -filter "DriveLetter='$($_.Drive)'"

    It is the only property that will match correctly.  Caption almost never matches on any two classes.   It is always necessary to find a property that is a common identifier.

    The caption on CDROMDrive is the full vendor name of the CD/DVD device.  Caption on Volume is the always the same as 'Name' of the drive.


    ¯\_(ツ)_/¯

    Monday, August 4, 2014 3:19 PM
  • Well, I see somebody does not really understand the issue here:

    gwmi win32_cdromdrive | select Drive

    will return me the drives on the local machine.

    But I do not care what they are, I only care the drive installed by Virtual CloneDrive with DeviceID

    SCSI\CdRom&Ven_ELBY&Prod_CLONEDRIVE&Rev_1.4\1&2afd7d61&0&000000

    at the end of the process be a specified letter ie. V

    In the beginning it can be anything (depending on system setup, no of physical drives, other virtual CD emulators etc)

    So I do not care if it is D or E or H or whatever. And I see no way to use

    -filter "DriveLetter='$($_.Drive)'"

    as I DO NOT KNOW what letter it is currently(for the script purposes to be used on many DIFFERENT systems)

    Logically I can only differentiate VCD CDROM drive by its Caption.

    Seb

    It is honestly pointless to do it all if one knows what the starting drive letter is

    I change G to V with Powershell, woopi!



    • Edited by scerazy Monday, August 4, 2014 7:00 PM
    Monday, August 4, 2014 6:50 PM
  • Monday, August 4, 2014 6:59 PM
  • Yes, please stop pointing to a class which can not be used in described situation (as it makes no sense)

    Either scripting with PS can do it or NOT?

    If it can then please help in useful manner.

    If it can't lets stop wasting time.

    I am by far NOT a scripting guy, hence asking for help

    sebus

    Monday, August 4, 2014 7:22 PM
  • Oh, my God; I'll take this one. I think what everyone is after is getting you to think this through. If you can get the drive letter from Win32_CDROMDrive class, then you'll know enough to change the drive letter. Take a look at my example.

    $IShouldBeLessRude = Get-WmiObject -Class Win32_CDROMDrive -Filter "Caption = 'ELBY CLONEDRIVE SCSI CdRom Device'" | Select-Object -ExpandProperty Drive
    
    $AskingForHelpRequiresIamLevelHeaded = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = '$($IShouldBeLessRude)'"
    
    Set-WmiInstance -InputObject $AskingForHelpRequiresIamLevelHeaded -Arguments @{DriveLetter="U:"}

    • Proposed as answer by Mike Laughlin Monday, August 4, 2014 7:46 PM
    • Marked as answer by scerazy Monday, August 4, 2014 7:55 PM
    Monday, August 4, 2014 7:29 PM
  • Yes, please stop pointing to a class which can not be used in described situation (as it makes no sense)

    Either scripting with PS can do it or NOT?

    If it can then please help in useful manner.

    If it can't lets stop wasting time.

    I am by far NOT a scripting guy, hence asking for help

    sebus

    What we are pointing at is the method you need to do you task.  You need to learn enough about Windows and scripting to understand the answer.

    You can choose the cdromdrive you are interested in by filtering for something that you think will identify it.  If the caption is the identifier then use the caption.  What you are missing is that the caption is not usable on Win32_Volume.  There is only one thing that links them in this situation and that is drive letter.  SO take the drive letter from you chosen CD and use it to select the volume whose drive letter you wish to change.  Once you have the related volume you can change the drive letter.

    Reading the blog post would have explained that.

    I showed you how to return the drive letter of the CD.  I also showed you how to filter the volume to get that device.

    The following works exactly as expected on my system.

    Get-WmiObject win32_cdromdrive -filter "Caption = 'hp DVD-RAM SW820 SCSI CdRom Device'" |
         ForEach-Object{
              Get-WmiObject Win32_Volume -filter "DriveLetter='$($_.Drive)'"
         }
    

    For more background on how to use PowerShell and WMI start here: http://technet.microsoft.com/en-US/scriptcenter/cc950497.aspx

    It is a pretty easy short video that gets you started.

    Here are more tutorials and resources: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Monday, August 4, 2014 7:46 PM
    • Marked as answer by scerazy Monday, August 4, 2014 7:55 PM
    Monday, August 4, 2014 7:38 PM
  • Thanks, nice and also works as expected.

    Appreciated, but took liberty of changing variable names (so they are shorter...)

    Seb



    • Edited by scerazy Monday, August 4, 2014 7:43 PM
    Monday, August 4, 2014 7:42 PM
  • Now we will address you need for returning a cloned drive.  How and where are you planning on querying.  Inside the VM it is just WMI as above.  External to the VM you need to add the VM network name (NetBIOS or dns) to the queries. 

    If you are on W8 or later then you can get the VM configuration using the VM CmdLets,

    As it stands you question is ambiguous and in conflict with what you have previously posted,  You will need to understand PowerShell and WMI and try to clearly ask your question.

    The answers we have been giving have been to you original post.  Your last statement about wanting the cloned adds confusion to your request.

    From inside of a VM there is no knowledge of the creator of a drive.  Drives appear to be just hardware although they all have generic names.


    ¯\_(ツ)_/¯

    Monday, August 4, 2014 7:46 PM
  • Of course more granular would be nice:

    Get-WmiObject -Class CIM_LogicalDevice -Filter "PNPDeviceID = 'SCSI\\CDROM&VEN_ELBY&PROD_CLONEDRIVE&REV_1.4\\1&2AFD7D61&0&000000'" | Select-Object Drive

    which would account for each instance of virtual drive, but CIM_LogicalDevice does NOT have Drive as property - http://wutils.com/wmi/ROOT/cimv2/CIM_ManagedSystemElement/CIM_LogicalElement/CIM_LogicalDevice.html

    even it shows in Powershell:

    Caption      : ELBY CLONEDRIVE SCSI CdRom Device
    Drive        : V:
    Manufacturer : (Standard CD-ROM drives)
    VolumeName   :

    Thanks, that was really useful (for me) to learn tonight

    Seb


    • Edited by scerazy Tuesday, September 30, 2014 12:22 PM
    Monday, August 4, 2014 7:59 PM
  • Virtual CloneDrive made by Elaborate Bytes - CD emulation software.

    Seb

    Monday, August 4, 2014 7:59 PM