≡ 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

 

Comments on this entry are closed.

  • 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?

    • Michael Lebeau May 2, 2017, 10:04 pm

      Nathan,

      Thanks for the code. I am having trouble getting it to run on workstations where I need it to run remotely. It will run well on any and all servers but not on any workstations. I am not sure why or what dependency is causing this. If I run the command on the workstation (Get-WmiObject Win32_MappedLogicalDisk -ComputerName Win10) it works as defined. Any clues?

      Michael

    • Ashwin September 7, 2017, 8:22 am

      Hi , it look like working

  • Sonny April 3, 2019, 7:00 am

    How about getting a list of shared drives for a specific user? I know the username I just need to know the shared drives they have access to?