Get SMB Mappings of ALL users

Welcome Forums General PowerShell Q&A Get SMB Mappings of ALL users

Viewing 17 reply threads
  • Author
    Posts
    • #249626
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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.

      • This topic was modified 1 month, 1 week ago by izShell57.
    • #249650
      Participant
      Topics: 8
      Replies: 568
      Points: 2,171
      Helping Hand
      Rank: Community Hero

      Apologies Isaac, I read that wrong.

    • #249662
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

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

    • #249680
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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.

    • #249683
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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.

    • #249698
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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?

    • #249704
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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”

    • #249707
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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.

    • #249710
      Participant
      Topics: 7
      Replies: 124
      Points: 600
      Helping Hand
      Rank: Major Contributor

      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.

    • #249713
      Participant
      Topics: 0
      Replies: 1
      Points: 5
      Rank: Member

      #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

      }

    • #249719
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

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

      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?

    • #249722
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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?

    • #249725
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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. 😉

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

      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. 😉

    • #249728
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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?

    • #249731
      Participant
      Topics: 7
      Replies: 124
      Points: 600
      Helping Hand
      Rank: Major Contributor

      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

    • #249737
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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.

    • #249740
      Participant
      Topics: 5
      Replies: 9
      Points: 68
      Rank: Member

      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.

    • #249767
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

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

Viewing 17 reply threads
  • You must be logged in to reply to this topic.