none
mapped drives script

    Pergunta

  • Does anyone have a mapped drives script, whereby supply domain/username as the paramter and it lists what drives they will have mapped on the PC they login to? I.e. network shares, home drives etc. It would be useful to do a script where we can supply a username as a parameter - and perhaps also do a monster report that lists all users in the domain and their mapped drives.

    Any pointers welcome.

    sexta-feira, 17 de fevereiro de 2012 11:15

Respostas

Todas as Respostas

  • Have you had a look in the repository, I found a script that checks the mapped drives but it requires both a machine and user name:

    http://gallery.technet.microsoft.com/scriptcenter/3dd6af3e-edfa-4581-bc35-805314f26bb8

    I believe it is hard to determine on which computer a user is logged on. The only way I know is to query every computer in your domain and report the logged in users. Because of that I think it would be hard to accomplish exactly what you are trying to do.

    What is the scenario you would like to use this script for?

    sexta-feira, 17 de fevereiro de 2012 11:42
  • Mapped drive information is only available for the currently logged on user.  It is not possible to check the mapped drives of a user that is not logged on.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    sexta-feira, 17 de fevereiro de 2012 12:54
  • You can combine the script JBrasser linked with this one that retrieves all computers in the domain:

    http://gallery.technet.microsoft.com/70c06176-5fd8-42fb-9d40-6a108f91d6d8

    Here is an example that queries for all computers, then pings each to see if it is available, then connects to each. You can replace what this does on each computer with the code in JBrasser's script:

    Option Explicit
    
    Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
    Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strComputer
    Dim objGroup, objMember, objShell, strLine, objComputer
    
    Set objShell = CreateObject("Wscript.Shell")
    
    ' Setup ADO objects.
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    Set adoCommand.ActiveConnection = adoConnection
    
    ' Search entire Active Directory domain.
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    strBase = "<LDAP://" & strDNSDomain & ">"
    
    ' Filter on computer objects, except Domain Controllers.
    strFilter = "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))"
    
    ' Comma delimited list of attribute values to retrieve.
    strAttributes = "sAMAccountName"
    
    ' Construct the LDAP syntax query.
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 200
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
    
    ' Run the query.
    Set adoRecordset = adoCommand.Execute
    
    ' Enumerate the resulting recordset.
    Do Until adoRecordset.EOF
        ' Retrieve values.
        strComputer = adoRecordset.Fields("sAMAccountName").Value
        ' Strip off trailing "$" character.
        strComputer = Left(strComputer, Len(strComputer) - 1)
        ' Ping computer to see if online.
        If (PingMachine(strComputer, 1, 750) = True) Then
            ' Bind to the local computer object remotely.
            On Error Resume Next
            Set objComputer = GetObject("WinNT://" & strComputer)
            If (Err.Number = 0) Then
                On Error GoTo 0
                ' Enumerate all local groups.
                objComputer.Filter = Array("group")
                For Each objGroup In objComputer
                    strLine = strComputer & "," & objGroup.Name
                    ' Enumerate direct members of the group.
                    For Each objMember In objGroup.Members
                        strLine = strLine & "," & objMember.Name
                    Next
                    Wscript.Echo strLine
                Next
            Else
                On Error GoTo 0
                Wscript.Echo strComputer & ", <Failed to bind to computer object>"
            End If
        Else
            Wscript.Echo strComputer & ", <Not available>"
        End If
        ' Move to the next record in the recordset.
        adoRecordset.MoveNext
    Loop
    
    ' Clean up.
    adoRecordset.Close
    adoConnection.Close
    
    Function PingMachine(ByVal strHost, ByVal intPings, ByVal intTO)
        ' Returns True if strHost can be pinged.
        ' Variable objShell has global scope
        ' and must be declared in the main program.
        ' Modified 09/14/2010 to search for "Reply from" instead of "TTL=".
    
        Dim strResults, objExecObject
    
        If (intPings = "") Then
            intPings = 2
        End If
        If (intTO = "") Then
            intTO = 750
        End If
    
        ' Ping the machine.
        Set objExecObject = objShell.Exec("%comspec% /c ping -n " _
            & CStr(intPings) & " -w " & CStr(intTO) & " " & strHost)
    
        ' Read the output.
        Do Until objExecObject.StdOut.AtEndOfStream
            strResults = objExecObject.StdOut.ReadAll
        Loop
    
        Select Case InStr(strResults, "Reply from")
            Case 0
                ' No response.
                PingMachine = False
            Case Else
                ' Computer responded to ping.
                PingMachine = True
        End Select
    End Function


    Richard Mueller - MVP Directory Services

    sexta-feira, 17 de fevereiro de 2012 12:56
  • Mapped drive information is only available for the currently logged on user.  It is not possible to check the mapped drives of a user that is not logged on.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    It is if yu load their regstry and look there.


    ¯\_(ツ)_/¯

    sexta-feira, 17 de fevereiro de 2012 15:51
  • It is if yu load their regstry and look there.


    ¯\_(ツ)_/¯

    Pray, do go on.  How would you do that?

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    sexta-feira, 17 de fevereiro de 2012 15:53
  • It is if yu load their regstry and look there.


    ¯\_(ツ)_/¯

    Pray, do go on.  How would you do that?

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    REG LOAD mytempid \\host\c$\<profilepath\ntuser.dat

    Yu can no accesw that hive as if it were a local hive. 

    If you have the hive loaded the user will not be able to logon with a profile and they ill be given a temporary profile.

    Yuo cannot load a hive if it is in use.


    ¯\_(ツ)_/¯

    sexta-feira, 17 de fevereiro de 2012 16:02
  • Cool!  So, having done that, you can now access the settings in Regedit or similar tools.  Have I got it right?  But what about mapped drives?  Where in the registry hive are they stored?

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    sexta-feira, 17 de fevereiro de 2012 16:16
  • That's what the VBScript in JBrasser's link does. It reads from the registry, although I haven't checked the key myself.


    Richard Mueller - MVP Directory Services

    sexta-feira, 17 de fevereiro de 2012 16:54
  • Cool!  So, having done that, you can now access the settings in Regedit or similar tools.  Have I got it right?  But what about mapped drives?  Where in the registry hive are they stored?

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    HKEY_CURRENT_USER\Network


    ¯\_(ツ)_/¯

    sexta-feira, 17 de fevereiro de 2012 16:56
  • That's what the VBScript in JBrasser's link does. It reads from the registry, although I haven't checked the key myself.


    Richard Mueller - MVP Directory Services

    The jbrasser script contains the keys but does not show how to use a custom loaded registry file.

    The file will be loaded on teh local machine and not remotel. 

    The script can be modified to work.

    I had to do this a number of years ago to fix some few hyndred hives.  Now that I am fairly proficient with custom ADM files I do this with Group Policy.  In WS2008 GP preferences are a real blessing to admins.


    ¯\_(ツ)_/¯

    sexta-feira, 17 de fevereiro de 2012 17:54