Announcement

Collapse
No announcement yet.

Logon Script with AD Groups

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

  • Logon Script with AD Groups

    Hi everyone, ive been editing this script and i think ive almost got it right but i am still getting an error
    Code:
    Dim objDomain, DomainString, UserString, UserObj, Path, objNetwork
    Set objShell = CreateObject("Wscript.shell")
    Set objNetwork = CreateObject("Wscript.Network")
    
    'Find Domain Name
    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    msgbox(DomainString)
    
    'Get User name
    UserString = objNetwork.UserName
    msgbox(UserString)
    
    'bind to the user object to get username 
    Set UserObj = GetObject("WinNT//" & DomainString & "/" & UserString)
    msgbox(UserObj)
    
    'Map Common Drives Drives - ie: General for Pheonix
    objNetwork.MapNetworkDrive "X:", "\\DC-PHX\Common" & UserString,True
    objNetwork.MapNetworkDrive "Y:", "\\DC-PHX\Data" & UserString,True
    msgbox("Mapped common drives")
    
    'Check Group and Map Drives
    For Each GroupObj In UserObj.Groups
    msgbox("In the for each")
    Wscript.Echo "You are logged on as " & objNetwork.Group
    Select Case GroupObj.Name
    
    Case "Managers"
    objobjNetwork.MapNetworkDrive "Z:", "\\DC-PHX\Managers" & UserString,True
    
    Case "HR"
    objNetwork.MapNetworkDrive "T:", "\\DC-PHX\Human_Resources" & UserString,True
    
    Case "Administrators"
    objNetwork.MapNetworkDrive "J:", "\\DC-PHX\Admin" & UserString,True
    
    end select
    
    next
    msgbox("Script Complete")
    wscript.exit

    They are not real names etc.

    I am having problems with this line"

    Code:
    Set UserObj = GetObject("WinNT//" & DomainString & "/" & UserString)
    it is saying invalid syntax

    Any help is very much appreciated

    Cheers Matty

  • #2
    Re: Logon Script with AD Groups

    My bad, just a bit of syntax error and a few colons and semi colons left out. Took a while to figure it out but it was staring me in the face.

    Code:
    on error resume next
    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,objNetwork
    Set WSHShell = CreateObject("Wscript.shell")
    Set WSHNetwork = CreateObject("Wscript.Network")
    
    'Find Domain Name
    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    'WinDir = wshShell.ExpendEnvironmentStrings("%Windir%")
    
    'Get User name
    
    UserString = WSHNetwork.UserName
    
    'bind to the user object to get username 
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
    
    
    'Map Common Drives Drives - ie: General for Pheonix
    WSHNetwork.MapNetworkDrive "X:", "\\DC-PHX\Common" ,True
    WSHNetwork.MapNetworkDrive "Y:", "\\DC-PHX\Data" ,True
    
    
    'Check Group and Map Drives
    For Each GroupObj In UserObj.Groups
    
    
    Select Case GroupObj.Name
    
    Case "Managers"
    WSHNetwork.MapNetworkDrive "Z:", "\\DC-PHX\Managers" ,True
    
    Case "grp-HR"
    WSHNetwork.MapNetworkDrive "T:", "\\DC-PHX\Human_Resources" ,True
    
    Case "Administrators"
    WSHNetwork.MapNetworkDrive "J:", "\\DC-PHX\SYSVOL" ,True
    
    end select
    
    next
    msgbox("Script Complete")

    Comment


    • #3
      Re: Logon Script with AD Groups

      I've tried using this, and it works...but I noticed if you are logged into more that one PC, it only maps the drives with the first PC you log into...at least thats what happens for me.

      Comment


      • #4
        Re: Logon Script with AD Groups

        Really, i havent had that problem as user havent been logging onto multiple computers. If it does happen i will let you know a fix (or if you find it before me post up here!)

        Cheers,
        Matt

        Comment

        Working...
        X