Announcement

Collapse
No announcement yet.

Script to report on current mapped drive connect

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to report on current mapped drive connect

    Has anyone found or written a script which will report back on a user's current mapped drives?
    I am about migrate an old file server to a new AD domain but am finding the data is all over the place with people being mapped to the same drives on different letters, some using H:\ for personal drives , others using H:\ to access public shares etc etc. I want to look at who has what before I move the data and connect everyone back with proper structured mappings.
    Last edited by Octagon; 10th April 2008, 14:37.

  • #2
    Re: Script to report on current mapped drive connect

    Perhaps this will do what you are looking for:

    The PsTools suite from SysInternals has a lot of great tools which can do all sorts of things on remote machines. Specifically, you will be interested in the PsLoggedOn tool. Download the full suite here:
    http://technet.microsoft.com/en-us/s.../bb896649.aspx

    From the PSLoggedOn information on said site:
    "PsLoggedOn is an applet that displays both the locally logged on users and users logged on via resources for either the local computer, or a remote one."

    You can also script this, I'm not sure if you have a known naming scheme for all computers...you will need the computer names. Let me know if I can help any more...but I think this will do the trick.

    As a side note...the PsShutdown is handy for remotely restarting machines. I particularly like scripting this one, when the machines in a computer lab shut down one by one in order, it's fun to watch!

    Have a great day.
    ~Kara
    ~Kara
    'What we do not make conscious emerges later as fate.' Carl Jung

    Comment


    • #3
      Re: Script to report on current mapped drive connect

      Thanks for that, I ran the tool but it doesn't output any network drive information, I have very little scripting knowledge so can't mod this to suit. I have all the computer names for the domain.

      Comment


      • #4
        Re: Script to report on current mapped drive connect

        How many computers are we talking about here? The reason I ask is because you can access mount points (mapped drives) from the registry. You can do this from a centralized workstation/server, by running regedit and going to File>Connect Network Registry, entering the computer name and browsing to the following key:
        HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\MountPoints2\

        The issue that comes up here with scripting is that since "HKCU" refers to the current user, if you're running regedit from a remote machine you can browse all the users keys, but not the "current user" that I know of.

        Anyway, what I am thinking here is that I could help you write a script which would export the correct registry key, and if you put it on a shared drive for all users, and instructed them to run it, you could gather data about what each user has mapped. This may end up being the simplest way. By the way, I did try that PsLoggedOn and saw that it didn't report the mapped drives, it only reports the shares being accessed by a user. Sorry about that!
        ~Kara
        'What we do not make conscious emerges later as fate.' Carl Jung

        Comment


        • #5
          Re: Script to report on current mapped drive connect

          This may seem old school but you could put a command in your logon script (assuming you use one) like this:

          net use >C:\netuse.txt

          This will output a list of all drive mappings on each computer to a file called netuse.txt in the root of the C: drive on each computer. You can then 'pick up" these files and review them. I'm sure someone with more scripting knowledge than me can come up with a script that names the files based on the user name and automates the collection of the files.

          Comment


          • #6
            Re: Script to report on current mapped drive connect

            thanks for the ideas chaps, I have been doing some digging around the registry to try and find the required info, the Key which holds the data is :

            HKCU\Network

            there are subkeys within that key which correspond to the network drive mapping info. Now all I need to do is try and bodge a script together to read it and output.

            Comment


            • #7
              Re: Script to report on current mapped drive connect

              Joe-Good idea!
              I forgot that net use by itself will report the mapped drives...I was making it much more difficult than needed-doh!


              Octagon,
              A really simple logon batch file will get you what you need, you could even redirect the text file to a share location which you make and everyone has access to if you wanted. I just tested this command:

              net use >\\servername\some_share\%username%Mapped.txt

              The %username% inserts the username into the name of the file. And the output's much easier to read than what you'd get with a reg file. Put that command inside a text file and save it as whatever.bat (make sure in the type drop down you select "all files") and you have yourself a script.

              You can put login scripts in either the local policy or group policy (group policy preferred since it's easier to manage). But I'm not sure you currently have a domain since you said you were migrating an old file server, is this old file server also on an existing domain?

              If you don't have a domain, I think the easiest thing to do would be to put the script out on a share that everyone can access and have them run it. Let them know they won't have their mapped drives if they don't

              By the way, might I suggest moving to a standard mapping scheme? I'm new at my company so I still can't remember what ours is...but across the board (we have 30 locations in the US) we have the same drive mapping (X to public, V to personal, etc). It helps, but there are always exceptions.

              ~Kara
              ~Kara
              'What we do not make conscious emerges later as fate.' Carl Jung

              Comment


              • #8
                Re: Script to report on current mapped drive connect

                Kara, I wasn't sure if the %username% variable would work or not. Thanks for pointing out that it does. That will make it easier as it can be piped to a network share as you suggested and have a uniquly named file for each user instaed of having to manually colect the files from each computer.
                Last edited by joeqwerty; 11th April 2008, 13:26.

                Comment


                • #9
                  Re: Script to report on current mapped drive connect

                  The subkeys under HKCU\Network are for the persistent mappings only.

                  If you want to see all mappings, here is joeqwerty's solution scripted for logonscript.
                  Code:
                  :: http://forums.petri.com/showthread.php?t=23061
                  
                  @echo off
                  
                  Set "destinationfile=\\unc\folder\NetUseCollection.txt"
                  
                  :dateparts (%yy% and %mm% and %dd%)
                  for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
                     for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
                        (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
                  
                  SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
                  
                  Set "userfolder=%userprofile%"
                  Set "flagP=NetUse %username%.flag"
                  Set "nwflag=%userfolder%\%yy%%mm% - %flagP%"  (add_or_remove dateparts to filename, see post)
                  
                  IF NOT EXIST "%nwflag%" (
                    For /f "tokens=*" %%* in ('dir /B "%userfolder%\*%flagP%" 2^>nul') Do (
                     Del /F "%userfolder%\%%*"
                    )
                    For /f "tokens=1*" %%i in ('net.exe use^|Find "\\"^|Find ":"') Do (
                     If /i "!firstline!" NEQ "done" (
                      > "%nwflag%" echo.%yy%-%mm%-%dd% %userdomain%\%username% [on %computername%]
                      >>"%nwflag%" echo.----------------------------------------------------------------
                     )
                     Set "firstline=done"
                     >>"%nwflag%" echo.%%i %%j
                    )
                    IF NOT EXIST "%destinationfile%" echo.>>"%destinationfile%"
                    >>"%nwflag%" echo.& >>"%nwflag%" echo.
                    IF EXIST "%destinationfile%" (
                      Copy "%destinationfile%"/b + "%nwflag%"/b "%destinationfile%"
                    )
                  )
                  
                  EndLocal
                  If you want to query the registry, to can use Reg.exe query in a batch.
                  Or you can write a vbscipt to collect more information.

                  \Rems
                  Last edited by Rems; 11th April 2008, 16:09. Reason: added the GREEN - !see also my next repy

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Script to report on current mapped drive connect

                    Thanks again all for the input, Rems that script is perfect, exactly what I was after.

                    who gets the karma?

                    Comment


                    • #11
                      Re: Script to report on current mapped drive connect

                      Thanks,

                      I do however want make a few adjustments to the batch.
                      The changes are in GREEN
                      Wat I do is add a datestamp to the flagfile name. So the script can refresh the file every day or every month or every year (depending which dateparts you append to the filename) in the example the file is going to be updated monthly.

                      note
                      I discovered one problem with this batch though!
                      - long UNC\folder names will break to new lines - and therefore it would only show the first part of the path in the output.


                      \Rems

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment

                      Working...
                      X