≡ Menu

PowerShell: How to get list of mapped drives

Mapped drives are the shares on remote computers for which you assigned a drive letter for easier access. We can query these drives and the target shares behind them with a simple and easy powershell one liner.

Here is the tip of the day. Happy Learning.

 

Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName

 

{ 4 comments… add one }
  • Alan October 24, 2012, 6:11 pm

    This is exactly what I needed in a pinch. Thanks for posting

  • Nathan February 23, 2017, 7:21 am

    Try this for Remote computers

    $computername = Get-Content ‘I:\NodeList\SNL.txt’
    $CSVpath = “C:\MSI\Mps.csv”

    remove-item $CSVpath

    $Report = @()

    foreach ($computer in $computername) {
    Write-host $computer
    $colDrives = Get-WmiObject Win32_MappedLogicalDisk -ComputerName $computer
    foreach ($objDrive in $colDrives) {
    # For each mapped drive – build a hash containing information
    $hash = @{
    ComputerName = $computer
    MappedLocation = $objDrive.ProviderName
    DriveLetter = $objDrive.DeviceId
    }
    # Add the hash to a new object
    $objDriveInfo = new-object PSObject -Property $hash
    # Store our new object within the report array
    $Report += $objDriveInfo
    }
    # Export our report array to CSV and store as our dynamic file name
    $Report | Export-Csv -NoType $CSVpath #$filenamestring
    }

    • Wintel Rocks February 25, 2017, 11:07 am

      Nathan,

      Thanks for sharing the code. How sure are you that it works?

      Mapped drives are specific to user login. You are referring to some other mappings here like drives mapped to folders?

Leave a Comment