Powershell 'Map' utility to display drive information

This function, called 'Map', will report on all logical drives on the local or remote computer, in text format. 

1,964 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • Odd Error on the "last" lines out output when I use this in my profile.
    1 Posts | Last post January 31, 2012
    • function DriveType($DriveCode) { 
          switch ($DriveCode) 
              { 0 {"Unknown"}  
              1 {"No root directory"}  
              2 {"Removable Disk"}  
              3 {"Local Disk"}  
              4 {"Network Drive"}  
              5 {"Compact Disk"}  
              6 {"RAM Disk"}  
              } # end switch 
          } # end function GetDriveType 
      function list-drivetype {
      Param (
      Get-WmiObject -Class win32_logicaldisk -ComputerName $strComputer | select DeviceID, VolumeName,`
          @{n='DriveType'; e={GetDriveType($_.driveType)}}, `
          @{n='Size';e={"{0:F2} GB" -f ($_.Size / 1gb)}}, `   
          @{n='FreeSpace';e={"{0:F2} GB" -f ($_.FreeSpace / 1gb)}} | Format-Table | Out-Default 
      Thats is what I "pasted" to my profile. Works great, but, one odd output, at the end. See that. 
      DeviceID   : X:
      VolumeName : ShadowCopyX_HOME3
      DriveType  :
      Size       : 75.00 GB
      Name                           Value
      ----                           -----
      n                              FreeSpace
      e                              "{0:F2} GB" -f ($_.FreeSpace / 1gb)
  • Error at the end of execution
    5 Posts | Last post November 10, 2011
    • out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with the default formatting.
          + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperationException
          + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
    • Worked for me on Win 7 SP1 with PS3 CTP1.  What OS/PS version are you using?
    • Hi Bryan, I can't imagine why you're getting that error.  It's just a simple Format-Table command.  Try it without the Format-Table, and check the results manually.
    • [1] Omit the Format-Table 
      [2] Append "|Out-String -s" after Format-Table.
      Should work 'consistantly' then.
    • Dave, why would that make it work consistently?