# Get SMB Mappings of ALL users

**URL:** <https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802>\
**Category:** PowerShell Help\
**Created:** [August 14, 2020, 7:15am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802 "2020-08-14T07:15:36Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 7:15am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/1 "2020-08-14T07:15:36Z")

</div>

Hello!

I am currently using the ‘wmic netuse’ to get the smb mappings of a machine. However, the command only returns the mappings for the current user. If I run my script as an administrator it returns nothing.

Is there a way to either:

1. Run the command in a way that will allow me to see the mappings created by any/all users. OR
2. Get a list of users, and run the individual command repeatedly as each user.

Thank you ahead of time for your help!

Additional Note: It is prefered that this is Powershell V2.0 compatible. Hence why I am using wmic instead of an SMB-related cmdlet.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [August 14, 2020, 7:39am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/2 "2020-08-14T07:39:35Z")

</div>

Apologies Isaac, I read that wrong.

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 8:35am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/3 "2020-08-14T08:35:47Z")

</div>

No problem!  
Hopefully you or someone else has an answer.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 10:07am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/4 "2020-08-14T10:07:44Z")

</div>

> [@](#):
>
> Additional Note: It is prefered that this is Powershell V2.0 compatible.

Since Microsoft has stopped supporting Windows 7, I don’t feel like doing that anymore

> [@](#):
>
> Run the command in a way that will allow me to see the mappings created by any/all users.

Drive mappings only exists inside the users sessions.

> [@](#):
>
> Get a list of users, and run the individual command repeatedly as each user

Of course you can get a list of users but it would be nearly impossible to impersonate each single use because you’d need all credentials. 😉

What is it actually what you’re trying to do? Usually there is another (quite ofter better) way of doing certain things.

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 10:19am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/5 "2020-08-14T10:19:26Z")

</div>

Unfortunately, this must be Powershell V2.0 compatible.  
I have clients who use Windows 7. It is not my choice.

What I’m trying to do is run the script as an administrator yet still get smbmappings that other users have.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 10:25am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/6 "2020-08-14T10:25:10Z")

</div>

> [@](#):
>
> What I’m trying to do is run the script as an administrator yet still get smbmappings that other users have.

OK but whatfor? What do you want to do with the smbmappings once you have them? Are these smbmappings individual ones or are they mapped by GPOs or logon scripts or something like this?

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 10:30am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/7 "2020-08-14T10:30:00Z")

</div>

I was asked to create an inventory script which will list the local and remote paths of smbmappings mapped to a machine.  
The file will look like this:  
“Local Path”, “Remote Path”  
“X:”, “\123.456.78.9”  
“Z:”,“\987.654.32.1\share”

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 10:36am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/8 "2020-08-14T10:36:23Z")

</div>

You could set up a logon script, run `net use` in that script and save the output to a share or on that local computer to collect the information you’re after.

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [August 14, 2020, 10:38am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/9 "2020-08-14T10:38:30Z")

</div>

If you want to get real ugly, you could enumerate all the NTUSER.DAT files on the system and glean the mount points from there. You can only of course do this for users that are not logged in.

Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2

A google search will get you info on how to mount the DAT file using PSDrive.

Although I agree with Olaf, if this is really important to get done, this method should work.

---

<div class="post-metadata">

**Author:** ![geminijef](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/geminijef/32/75_2.png) [@geminijef](https://forums.powershell.org/u/geminijef)\
**Post date:** [August 14, 2020, 10:50am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/10 "2020-08-14T10:50:24Z")

</div>

#You can run something like this:

#get a list of all your computers in a variable

$computers = get-content -path C:\temp\computers.csv

#list all the mapped drives with the associated computername (systemname)

foreach ($computer in $computers) {

gwmi win32\_mappedlogicaldisk -computername $computers |

select-object deviceid,providername,systemname

}

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 11:01am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/11 "2020-08-14T11:01:18Z")

</div>

Jeffrey, welcome to [Powershell.org](http://Powershell.org). Please take a moment and read the very first post on top of the list of this forum: [Read Me Before Posting! You’ll be Glad You Did!](https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did).

When you post code, error messages, sample data or console output format it as code, please.  
In the “ **Text** ” view you can use the code tags “ **CODE** ”, in the “ **Visual** ” view you can use the format template “ **Preformatted** ”. You can go back edit your post and fix the formatting - you don’t have to create a new one.  
Thanks in advance.

> [@](#):
>
> #list all the mapped drives with the associated computername (systemname)

If I’m not wrong that would only list the mapped drives for the account you’re running the commands with as well - not the mapped drives of all users of the remote computers, right?

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 11:03am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/12 "2020-08-14T11:03:59Z")

</div>

Hey Olaf,

When you say logon script do you mean, a script which will log on to each account and collect the information one after another?

Hey Tony,  
Thank you for your responce. That does sound quite indimidating!  
But if all else fails, I may need to look into it.

Hey Jeff,  
I do not understand the first line of your code.  
Where does this file come from?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 11:15am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/13 "2020-08-14T11:15:11Z")

</div>

> [@](#):
>
> When you say logon script do you mean, a script which will log on to each account and collect the information one after another?

No. A logon script runs when a user logs on to a computer and executes the commands in this script. You would need to wait until all users have logged in at least once. 😉

[quote quote=249722]Hey Jeff,  
I do not understand the first line of your code.  
Where does this file come from?[/quote]  
Jeff commented his code. The first line reads a file containing a list of computers you want to query. I assume that does not fit your requirement. 😉

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 11:24am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/14 "2020-08-14T11:24:26Z")

</div>

Hello Olaf,

I cannot wait for users to logon unforunately. This needs to run once upon installation of an app.

And in refernce to Jeff’s comment. I tried the first query (get-Content of that file) but the file could not be found.  
That is why I was confused.  
Am I creating the file? Or does it already exist on a machine?

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [August 14, 2020, 11:26am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/15 "2020-08-14T11:26:33Z")

</div>

Maybe not so daunting … this should get you the DAT files (as admin of course):

`Get-ChildItem -Path ‘C:\users’ -Name ‘NTUSER.DAT’ -Depth 1 -Hidden -Force`

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 11:46am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/16 "2020-08-14T11:46:20Z")

</div>

> [@](#):
>
> I cannot wait for users to logon unforunately. This needs to run once upon installation of an app.

That will make your task much more challenging. 😉

> [@](#):
>
> And in refernce to Jeff’s comment. I tried the first query (get-Content of that file) but the file could not be found.

Please don’t get me wrong but that sounds like you are quite a beginner with Powershell. The task you choose is not an easy one I’d say. You may take a step back and start with learning the very basics of Powershell first. That will save you from a lot of wasted time and frustration.

It is beyond the scope of this or any forum to develop a custom solution for your requirement and we cannot teach you how to write advanced scripts iteratively in a forum.

---

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 14, 2020, 11:54am UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/17 "2020-08-14T11:54:07Z")

</div>

You’re correct. I am definitely a beginner.  
However, I have been learning a lot on my own time.  
In addition, this isn’t for fun (as you might imagine). I’m being asked to do this for work. (aka fustration will be inherent in this task lol).  
This forum has been helpful, not in giving me custom solutions but in helping my general understanding.

And specifically to Jeff’s comment, I just didn’t understand what he was refering to.

I don’t mean to sound defensive or offensive with any of this.  
Just stating my current situation.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 14, 2020, 3:35pm UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/18 "2020-08-14T15:35:47Z")

</div>

OK, so you will have to find a way to achieve the almost impossible or to find a way around it. 😉 You mentioned this should run as a part of an installation of an app. Why would need an app the information about ALL users smb mappings? I’d expect it should be enough to know about the smb mappings of the currently logged on user.

Edit:  
And what’s about users logging on after the app was installed? 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/get-smb-mappings-of-all-users/14802/19 "2024-05-16T20:29:04Z")

</div>


