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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve Deparment and map network printer accordingly

Status
Not open for further replies.

dannyd74

MIS
Nov 25, 2003
23
0
0
US
I have very minimal vbscript knowledge, and I was asked to come up with a script that will retrieve the user's Department in AD, and assign network printers accordingly. Our AD isn't structured well, and all users sit in the USER container and are not separated by OUs. Any help would be great!
 
Here's a look at some of what I have, but I don't want to determine the OU. I want to determine the Department!


'Determining OU Name
Set objSysInfo = CreateObject("ADSystemInfo")
UserADsPath = objSysInfo.UserName

arrTemp = split(UserADsPath,",")
OUName = arrTemp(1)


'Mapping the Drive
if OUName = Human_Resources Then

Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\Server\Printer"
Else
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\Server\Printer"
End if
 
it tells me ...Object doesn't support this property...'objSysInfo.Department' on that line.
 
OK, i did not get a chance to test this but try this script. You will have to change some of the OU= stuff and the wscript.echo things, but it should help get you in the right direction. You need to be able to query the AD for the Username. once you do that you can return the object.properties (or in this case 'department')

'create the strUsername to use later
Set objNetwork = WScript.CreateObject("WScript.Network")
strUsername = objNetwork.username

'Test it
WScript.Echo strusername

' put the strUsername in the query where it belongs
'
' (will have to change OU= and dc= values)
Set objUser = GetObject _
("LDAP://cn="& strusername &",ou=portal,dc=staging,dc=com")
objUser.GetInfo
strDepartment = objUser.Get("department")

'Test again
WScript.Echo strDepartment

'Mapping the Drive
if strDepartment = "Human_Resources" Then
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\Server\Printer"
Else
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\Server\Printer"
End if
 
You know i starting thinking about it. you could create an HR_printers group in AD, and apply a policy to that group that would have just the last part of your script as a start up script.
 
u might end up having multiple scripts running for multiple groups, might slow things down a bit

we have location, ad group and user ini files which can have the following entries

[MapPrinters]
EnabledLocal=1
EnabledRemote=0
LoggingRemote=eventlogonly
LoggingLocal=file&eventlog

; **** 2nd Floor
BRAPRINT2NOV=\\servername\BRAMIS5SIBP&NoDisconnect
BRAPRINT2NOV%3=\\servername\BRAMIS4P3BP&NoDisconnect
BRAPRINT2NOV%4=\\servername\BRAITS4550CP&NoDisconnect

The map printer component can be turned on or off based on connection type and the group ini can override the location.ini and the user ini can override them all etc etc
 
I'm very limited in the freedom I have on the Domain Controllers. The script is not going to be implemented via login, but rather as we deploy the new machines to the users. I'm just going to make it a task of the team setting up the new 2k workstations to double-click on the vbs file to install the printers. I'm tweaking some the examples posted now. I will keep updating.
 
I tested both methods on my Windows Millennium Edition workstation and Windows 2000 Server with AD and here are the results:

First suggestion:
I get a Microsoft VBScript runtime error "ActiveX component can't create object: 'ADSystemInfo'" Code: "800A01AD"

Second suggestion:
cmwoodman, since I already create WScript.Network in my login script, I decided to try that. But I get an error with this code too but I'm sure it's because I can't figure out how to phrase the GetObject parameters (the docs I found and looked at for GetObject indicated only 2 parameters are used, but you showed 4. What would be a "real world" example...
Code:
Dim objUser
' (will have to change OU= and dc= values)
Set objUser = GetObject _
  ("LDAP://cn="& strUserName &",ou=portal,dc=staging,dc=com")
objUser.GetInfo
strDepartment = objUser.Get("department")
dbMark
 
I will test this at work sometime this week and update. Thanks again for your help. With the holidays, I haven't been able to do a whole lot with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top