Drive letter of the volume in PS RRS feed

  • Question

  • get-volume outputs FriendlyName

    DriveLetter FriendlyName     FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining      Size
    ----------- ------------     -------------- --------- ------------ ----------------- -------------      ----
    F           LEXAR            FAT32          Removable Healthy      OK                     11.87 GB  14.89 GB

    But I cannot use it in batch:

    for /f %%a in (
      'c:\Windows\system32\WindowsPowerShell\v1.0\powershell "(get-volume | where FriendlyName -eq "LEXAR").driveletter"'
    ) do set IMGVOL=%%a

    returns nothing:

    C:\PSScripts>for /F %a in ('c:\Windows\system32\WindowsPowerShell\v1.0\powershell "(get-volume | where FriendlyName -eq "LEXAR").driveletter"') do set IMGVOL=%a
    C:\PSScripts>echo %IMGVOL%

    Why is that?



    In the end I had to use:

    for /f %%a in (
      'c:\Windows\system32\WindowsPowerShell\v1.0\powershell "(Get-WmiObject Win32_Volume | where Label -eq "LEXAR").driveletter"'
    ) do set IMGVOL=%%a

    • Edited by scerazy Saturday, July 6, 2019 3:31 PM
    Saturday, July 6, 2019 3:27 PM


All replies

  • (get-volume -FileSystemLabel LEXAR).Driveletter


    • Marked as answer by scerazy Tuesday, July 9, 2019 5:40 AM
    Saturday, July 6, 2019 6:51 PM
  • Thanks, but would like to understand why

    get-volume | where FriendlyName -eq "LEXAR").driveletter

    does NOT work? (even it is displayed)

    • Edited by scerazy Sunday, July 7, 2019 4:20 AM
    Sunday, July 7, 2019 4:20 AM
  • Because it is not a property.  It is a decoration added by the default formatter for the CmdLrt.

    Try this:

    get-volume |Format-Custom

    "FriendlyName" does not exist.


    Sunday, July 7, 2019 4:40 AM
  • Thank you. So that is one of those helpful (cause it looks better), but not really of much use

    Great explanation

    Tuesday, July 9, 2019 5:40 AM