Get SMB Mappings of ALL users


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.

Apologies Isaac, I read that wrong.

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

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

Drive mappings only exists inside the users sessions.

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. :wink:

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

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.

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?

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”

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.

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.


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.

#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


Jeffrey, welcome to 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!.

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.

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?

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?

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. :wink:

[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. :wink:

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?

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

That will make your task much more challenging. :wink:

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.

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.

OK, so you will have to find a way to achieve the almost impossible or to find a way around it. :wink: 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.

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