none
How to catch my drive letter RRS feed

  • Question

  • Hello,

    I've some problem to know the letter drive I've mounted :

    $Drive = (Mount-VHD -Path x:\myvhd.vhdx -ErrorAction SilentlyContinue -PassThru | Get-Disk | Get-Partition).DriveLetter

    Copy-Item D:\myfile $Drive + ":\file"

    I've some object type problem : can't convert System.Object in System.string

    Any help is welcome,

    Regards

    • Moved by Bill_Stewart Wednesday, October 18, 2017 8:06 PM Abandoned
    Thursday, August 31, 2017 2:12 PM

All replies

  • http://windowsitpro.com/hyper-v/q-what-my-vhd-files-drive-letter
    Thursday, August 31, 2017 2:22 PM
  • A Brief Introduction to Drive Letter

    A drive letter is a single alphabetic character A through Z that can be assigned to physical disk partition, floppy disk drive, removable device, CD-ROM, or even a mapping network drive in the computer. Generally, drive letter A: is allocated to the first floppy disk drive , B: to the second floppy disk drive, and C: to the first disk partition where the running Windows is installed. And the remaining drive letters can be assigned to other disk partitions, removable devices and mapping network drives in accordance with actual demands. 

    Once a letter is allocated to a disk partition or mapping network drive (letter for removable devices is changeable), we can say it is fixed unless we change or remove it in Disk Management, Diskpart, or some third party programs. 

    However, one day we may find these fixed drive letters are missing in either Windows Explorer or Disk Management, which brings much inconvenience or even makes the partition inaccessible. 

    Therefore, we wrote this post and introduce 5 different situations where drive letter disappears, and at the same time show ways to get the missing letter back. 

    you should check this article - https://www.partitionwizard.com/partitionmanager/drive-letter-is-missing-in-windows.html

    Thursday, August 31, 2017 2:23 PM
  • Copy-Item D:\myfile ($Drive + ":\file")
    Try this

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, August 31, 2017 3:02 PM
  • Thks for your answer, but my question is not about a lost drive or letter but it seem to me that it's a problem of type of object ... I've tested  :

    gwmi Win32_DiskPartition -filter "DeviceID like 'Disk #$DiskNumber,%'").PSBase.GetRelated('Win32_LogicalDisk') | Select-object -ExpandProperty DeviceID

    but I've another error like : [System.Management.Automation.PSInternalMemberSet] has no method GetRelated ..

    Thursday, August 31, 2017 3:07 PM
  • $Drive = (Mount-VHD -Path myvhd -ErrorAction SilentlyContinue -PassThru | Get-Disk | Get-Partition).DriveLetter

    Copy-Item D:\myfile ($Drive + ":\file")

    same pb :

     Impossible to convert «System.Object[]» to «System.String»

    Thursday, August 31, 2017 3:15 PM
  • $vhd = Mount-VHD -Path x:\myvhd.vhdx -PassThru
    $driveletter = ($vhd|get-Disk|Get-Partition).Driveletter[1]
     "$($driveletter):file"

    Start be removing the ErrorAction.

    Do in steps and inspect what you get.

    "DriveLetter" returns an array with two elements.


    \_(ツ)_/


    • Edited by jrv Friday, September 1, 2017 7:11 AM
    Thursday, August 31, 2017 4:54 PM
  • I am in windows 2012r2 and powershell :

    PSVersion                      4.0                                                                                         
    WSManStackVersion              3.0                                                                                         
    SerializationVersion           1.1.0.1                                                                                     
    CLRVersion                     4.0.30319.34014                                                                             
    BuildVersion                   6.3.9600.17400   

    If you do this alone :

    $vhd = Mount-VHD -Path x:\myvhd.vhdx

    You get nothing for $vhd ...

    Friday, September 1, 2017 7:09 AM
  • Just add -PassThru to that line,


    \_(ツ)_/

    Friday, September 1, 2017 7:11 AM