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

Another GPO vbscript

Status
Not open for further replies.

JinNjuicE

Programmer
Jan 7, 2004
6
US
i am testing a simple printer/netdrive logon script. here is the code...

-CODE---------------------------------------------------
option explicit
on error resume next

dim oNet, adsi, curUser

const cert_group = "OU=ACCESSBILITY GROUP"
const fin_group = "OU=FINANCE SUPPORT GROUP"
const test_group = "OU=TESTHQ"

set oNet = CreateObject("Wscript.Network")

set adsi = CreateObject("ADSystemInfo")
set curUser = GetObject("LDAP://" & adsi.UserName)

oNet.MapNetworkDrive "T:", "\\Server\Share"

'Cert
if instr(adsi.username, cert_group) then
oNet.MapNetworkDrive "P:", "\\Server\Share"
oNet.AddWindowsPrinterConnection "\\Server\Printer"
oNet.SetDefaultPrinter "\\Server\Printer"
'Finance
elseif instr(adsi.username, fin_group) then
oNet.AddWindowsPrinterConnection "\\Server\Printer"
oNet.SetDefaultPrinter "\\Server\Printer"
'TESTHQ
elseif instr(adsi.username, test_group) then
oNet.MapNetworkDrive "N:", "\\Server\Share"
oNet.AddWindowsPrinterConnection "\\Server\Printer"
oNet.SetDefaultPrinter "\\Server\Printer"
Wscript.Echo "TESTHQ - Executed"
end if

set oNet = nothing
set adsi = nothing
set currentUser = nothing

-CODE---------------------------------------------------

i have created a test user in 'TESTHQ' OU. The script gets executed through GPO (Echo gets executed), but it doesnt add printers.
 
I'm guessing that the script is not detecting your user groups.

Give this script a try:

'==========================================================================
'
' NAME: LogonScript
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================


ON ERROR RESUME NEXT

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
DomainString = "DomainName"
UserString = WSHNetwork.UserName

Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"


WSHNetwork.RemoveNetworkDrive "F:"

wscript.sleep 300

'Maps drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups

Select Case GroupObj.Name
'Check for group memberships and take needed action
Case "Admin"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WorkerB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True

End Select

Next


'Install Printers

WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"



set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing

wscript.quit


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thank you Mark.

If I am not mistaken, your script assigns attributes by grouping user's security/builtin groups.

I am sorry if I wasn't too clear on what my script is for. My script is designed to assign printers and network drives by grouping Organizational Units (all of our OUs have unique names).

To test out my script, I logged into a workstation with a TESTUSER account (TESTUSER is in the "TESTHQ" OU). I can see the echo "TESTHQ - Executed". Just to make sure that the script was picking up the right OU group, I inserted ECHO statements in different group also. The script maps correct network drives, but it doesnt map printers at all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top