How to show currently mapped drives in PowerShell?

66,272

Solution 1

In PowerShell 5 (Windows 10) and above, use:

Get-SMBMapping

https://docs.microsoft.com/en-us/powershell/module/smbshare/get-smbmapping?view=win10-ps

Solution 2

On the assumption that you do not wish to exclude drives that point to the local filesystem, I believe that

Get-PSDrive -PSProvider FileSystem | Select-Object name, @{n="Root"; e={if ($_.DisplayRoot -eq $null) {$_.Root} else {$_.DisplayRoot}}}

will serve your need. If you do wish to exclude drives that point to the local filesystem, you may find

Get-PSDrive -PSProvider FileSystem | Select-Object Name, DisplayRoot | Where-Object {$_.DisplayRoot -ne $null}

to be more to your liking.

Solution 3

TryNET USE command from Powershell

Ok. net use worked. I can swear I tried that before and it did not work. I think this is because I was trying to map a network drive last time I used net use. – Kolob Canyon

Share:
66,272

Related videos on Youtube

Kellen Stuart
Author by

Kellen Stuart

Updated on September 18, 2022

Comments

  • Kellen Stuart
    Kellen Stuart over 1 year

    Need a PowerShell command to display drive letter and path it is mapped to.

    In other words a command that shows me the same thing Windows Explorer would.

    Tried this:

    Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName
    

    and it is missing several drives (listed in Windows Explorer).

    • Zoredache
      Zoredache over 7 years
      Does Get-PSDrive show these missing drives? Is there something special or weird about these drives that are missing? Are they all mappings to a Windows server?
    • Jeff Zeitlin
      Jeff Zeitlin over 7 years
      Do you specifically wish to exclude local filesystem drives?
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 7 years
      How about a good old NET USE command from Powershell or a command prompt?
    • Kellen Stuart
      Kellen Stuart over 7 years
      @ITSolutions net use doesn't work in Powershell... unless you drop into cmd prompt
    • Kellen Stuart
      Kellen Stuart over 7 years
      @Zoredache I can see the missing drive letters under the name column for Get-PSDrive command. The provider isn't showing me the path to them. Tried to select the ProviderName from Get-PSDrive and no dice
    • Zoredache
      Zoredache over 7 years
      What do you mean 'net use` doesn't work under powershell? It works perfectly fine. Perhaps you should spend some type in your question elaborating about why you need this, and how these particular drives were mapped in the first place. Additional context may help us figure out what the problem is and get you an answer.
    • Lieven Keersmaekers
      Lieven Keersmaekers over 7 years
      Instead of mentioning what you see it would be far mor helpfull to actually show what you see. Post a screenshot of your explorer window and the output of Get-PSDrive.
    • Kellen Stuart
      Kellen Stuart over 7 years
      @Zoredache Ok. net use worked. I can swear I tried that before and it did not work. I think this is because I was trying to map a network drive last time I used net use.
    • Josiah DeWitt
      Josiah DeWitt about 3 years
      You won't see mapped network drive in PS or CMD when you run as Administrator
  • Kellen Stuart
    Kellen Stuart over 4 years
    I'm going to accept this as the answer because this most directly answers the question (e.g. using powershell Cmdlets)