Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Computer Group Script 2

Status
Not open for further replies.

kdibricida

Technical User
Jun 15, 2005
24
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.
 
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
 
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.
 
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
 
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 & "/" & [red]strComputer[/red])

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
 
Ah man, spoiled my fun of finally correcting you....
 
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 = "[URL unfurl="true"]http://manpmsap"[/URL]
			MyShortcut.WindowStyle = 4
			MyShortcut.IconLocation = "\\manpmsap\client\OPERA.ico"
			MyShortcut.Save
  End Select
Next

I hope you find this post helpful.

Regards,

Mark
 
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 
[red]Set[/red] 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 = "[URL unfurl="true"]http://manpmsap"[/URL]
        MyShortcut.WindowStyle = 4
        MyShortcut.IconLocation = "\\manpmsap\client\OPERA.ico"
        MyShortcut.Save
 End Select
Next

I hope you find this post helpful.

Regards,

Mark
 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top