×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Get Computer Group Script
2

Get Computer Group Script

Get Computer Group Script

(OP)
I am trying to run a logon script that performs the following based on what group a computer is a member of.  

1.  Map network printers
2.  Set default printer
3. Network Drives

I want to use this script in a site policy and perform certain actions based on what computer a user is logging onto.  

I know how to perform the above actions, but i am having trouble figuring out how to find the computer group membership.  

RE: Get Computer Group Script

2
my FAQs FAQ329-5908 and FAQ329-5798 should give you all you need to get the job done.

You enumerate computer group memberships the same way you do user object group memberships.  So just follow that example.

I hope you find this post helpful.  

Regards,

Mark

RE: Get Computer Group Script

(OP)
Thanks But I am not following how to use this for computers.  I had previously used these articles to develop scripts for other locations.  I am new to scripting and they were very helpful.

I am not sure what i would change to make this work for computers.

RE: Get Computer Group Script

Like this:

CODE


Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
strComputer = WSHNetwork.ComputerName
Set ComputerObj = GetObject("WinNT://" & DomainString & "/" & UserString)

For Each GroupObj In ComputerObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
        Case "AdminPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
            'Below is an example of how to set the default printer
            WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
    End Select
Next

I hope you find this post helpful.  

Regards,

Mark

RE: Get Computer Group Script

Correction to the above script which was a modified version of my other scripts.  

CODE

Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
strComputer = WSHNetwork.ComputerName
Set ComputerObj = GetObject("WinNT://" & DomainString & "/" & strComputer)

For Each GroupObj In ComputerObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, ADMINPC and WORKERPC are groups.
        Case "AdminPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
            'Below is an example of how to set the default printer
            WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
    End Select
Next

I hope you find this post helpful.  

Regards,

Mark

RE: Get Computer Group Script

Ah man, spoiled my fun of finally correcting you....

RE: Get Computer Group Script

Posting some new code for the above solution based on some private support I've been lending to one of the other readers.

CODE


Dim WSHShell, objNET, objSysInfo, objComputer, strComputerDN, strGroups, Group, GroupName
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objNET = WScript.CreateObject("WScript.Network")
Set objSysInfo = WScript.CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.COMPUTERNAME
Set objComputer = GetObject("LDAP://" & strComputerDN) 'Binds the objComputer to the Distiguished Name of the Computer in reference   

strGroups = objComputer.GetEx("memberOf ")   
For Each Group in strGroups
  ThisGroup = GetObject("LDAP://" & Group)
  GroupName = ThisGroup.CN
  
  Select Case GroupName
          Case "AdminPC"
            objNET.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerPC"
            objNET.MapNetworkDrive "w:", "\\Server\Shared Documents",True
            'Below is an example of how to set the default printer
            objNET.SetDefaultPrinter "\\ServerName\PrinterName"
        Case "JanitorPC"
            strStatus = strStatus & vbCRLF & "Member of Opera Users"
            ie.document.all.wstatus.InnerText = strStatus
            DesktopPath = WSHShell.SpecialFolders("Desktop")
            Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\Opera PMS.lnk")
            MyShortcut.TargetPath = "http://manpmsap"
            MyShortcut.WindowStyle = 4
            MyShortcut.IconLocation = "\\manpmsap\client\OPERA.ico"
            MyShortcut.Save
  End Select
Next

I hope you find this post helpful.  

Regards,

Mark

RE: Get Computer Group Script

Last go around after further testing.  Sure wish I could just edit previous posts!

CODE

Dim WSHShell, objNET, objSysInfo, objComputer, strComputerDN, strGroups, Group, GroupName
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objNET = WScript.CreateObject("WScript.Network")
Set objSysInfo = WScript.CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.COMPUTERNAME
Set objComputer = GetObject("LDAP://" & strComputerDN) 'Binds the objComputer to the Distiguished Name of the Computer in reference   
  
strGroups = objComputer.GetEx("memberOf ")   
For Each Group in strGroups
Set ThisGroup = GetObject("LDAP://" & Group)
 GroupName = ThisGroup.CN
 
 Select Case GroupName
   Case "AdminPC"
           objNET.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
   Case "WorkerPC"
           objNET.MapNetworkDrive "w:", "\\Server\Shared Documents",True
           'Below is an example of how to set the default printer
           objNET.SetDefaultPrinter "\\ServerName\PrinterName"
  Case "JanitorPC"
        strStatus = strStatus & vbCRLF & "Member of Opera Users"
        ie.document.all.wstatus.InnerText = strStatus
        DesktopPath = WSHShell.SpecialFolders("Desktop")
        Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\Opera PMS.lnk")
        MyShortcut.TargetPath = "http://manpmsap"
        MyShortcut.WindowStyle = 4
        MyShortcut.IconLocation = "\\manpmsap\client\OPERA.ico"
        MyShortcut.Save
 End Select
Next

I hope you find this post helpful.  

Regards,

Mark

RE: Get Computer Group Script

(OP)
Thanks for the scripts worked well for me.

Do you know of a script to change passwords on services?  We have some apps that run under an account that we need to change the password every 30 days.  Do you know if there is a script i could use to change these easily.

RE: Get Computer Group Script

Recommend starting a new thread for this issue, as you're comment could very well be missed out.

As for your issue:

CODE

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where StartName = '.\\netsvc'")

For Each objService in colServiceList
    errReturn = objService.Change( , , , , , , , "password")  
Next

came from
http://www.microsoft.com/technet/scriptcenter/scripts/os/default.mspx

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close