Tech Support banner

Status
Not open for further replies.
1 - 1 of 1 Posts

·
Registered
Joined
·
2 Posts
Discussion Starter #1
Hi! I need some help on this script i want to use to assign automaticly default printers to spesific groups. You see, i have 3 rooms with separate printers and about 30 thin clients in each room.
Now, i want a script that automaticly checks to see if a computer is a member of a spesific group and if it is, it'll set the default printer.

I have a script that is supposed to do this, but it doesn't seem to work. Would anyone mind looking at the script to check if there's anything i'm missing?

Code:
' Script begins here
Dim objNetwork, objComputer, strDomain, strComputerName
' * Replace string with domain name of your network
strDomain = "RINGVE"
' Main object to use
Set objNetwork = CreateObject("Wscript.Network")
' Picks up computer name
strComputerName = objNetwork.ComputerName
' Load referance to our computer
Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer")
' First, checks to see if the computer is a member of the first group
If IsGroupMember(strDomain, "Group1") Then ' Replace "Group1" with the first group
objNetwork.SetDefaultPrinter "Laserprinter AA05" ' Write name of the printer to be attached to the first group
' If that's not the case, checks to see if it's a member of the next group
ElseIf IsGroupMember(strDomain, "Group22") Then ' Same here ...
   objNetwork.SetDefaultPrinter "Laserprinter AA07" ' Same here, ...
' If this is not correct, There's only one group left. Unless do nothing
ElseIf IsGroupMember(strDomain, "Group3") Then ' Same here ...
   objNetwork.SetDefaultPrinter "Laserprinter AA08" ' Same here, ...
  
End If
' Clean up
Set objNetwork = Nothing
Set objComputer = Nothing
Wscript.Quit
Function IsGroupMember(strDomain, strGroup)

   Dim objGroup
   
   ' Object that makes it possible to check group membership
   Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
   
   ' Returns result about computer being a member av a group
   IsGroupMember = objGroup.IsMember(objComputer.ADsPath & "$")
   
   ' Clean up
   Set objGroup = Nothing

End Function
Can anyone see some errors? Cause the script don't set the default printer although the thinclient i'm curretly sitting on is a member of "Group1" so I'm thinkin' it must be something about the syntax or something? That the script simply don't understand where the groups are or don't understand the computername? Or is it something about the thin clients? Cause the thin client is registered in Active Directory and is a member of the first group.
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top