Hi,
I am hoping someone could help me out with a vbscript. This is my first one and I am having trouble adding printers and mapped drives according to a users windows security group.
When I execute the script it will map the printers and drives for the first security group regardless if the user is a member or not then it will end.
Any advice is greatly appreciated.
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME:
'
' AUTHOR:
' DATE : 7/8/2004
'
' COMMENT: Test script
'
'==========================================================================
Option Explicit
Dim objNetwork, sysinfo, CurrentUser
Dim strGroups
Const it = "cn=tim it management"
Const adminstrative = "cn=tim administrative"
Const ops = "cn=tim ops managers"
Const exec = "cn=tim corp exec"
Const finance = "cn=tim finance"
Set objNetwork = CreateObject("WScript.Network")
' Forces script to skip errors (rem below line to see errors)
on error resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
' SET ALL DRIVES TO BE REMOVED HERE
WshNetwork.RemoveNetworkDrive "G:"
WshNetwork.RemoveNetworkDrive "N:"
WshNetwork.RemoveNetworkDrive "O:"
WshNetwork.RemoveNetworkDrive "R:"
' Set ALL NETWORK PRINTERS TO BE REMOVED HERE
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP laserjet 8000"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Color Laserjet 4550C"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Laserjet 2200 (Ops)"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP laserjet 2200 (Paul)"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Laserjet 4050"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP8000"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP4550"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP2200ops"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP2200P"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP4050"
' THIS LINE WILL RETRIEVE USERS AD INFO
Set sysinfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & sysinfo.UserName & "")
strGroups = LCase(Join(CurrentUser.MemberOf))
' SETTING ALL NETWORKDRIVES THAT ARE ASSIGNED TO ALL USERS
objNetwork.MapNetworkDrive "g:", "\\dc2a\g"
objNetwork.MapNetworkDrive "n:", "\\dc2a\n"
' objNetwork.MapNetworkDrive "z:", "\\servername\Users\" & objNetwork.UserName
' SETTING ALL PRINTERS ASSIGNED TO ALL USERS
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP8000"
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP4550"
' EXTRA PRINTERS FOR SPECIFIC SECURITY GROUP
If InStr(strGroups, administrative) Then
' WScript.Echo("Made it To administrative")
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.SetDefaultPrinter "\\atlantis\HP8000"
Elseif InStr(strGroups, finance) Then
' WScript.Echo("Made it To finance")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP4050"
' WshNetwork.SetDefaultPrinter "\\atlantis\HP4050"
Elseif InStr(strGroups, ops) Then
' WScript.Echo("Made it To OPs")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200ops"
WshNetwork.SetDefaultPrinter "\\atlantis\HP2200ops"
Elseif InStr(strGroups, exec) Then
' WScript.Echo("Made it To Corp Exec")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
' WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200P"
Elseif InStr(strGroups, it) Then
WScript.Echo("made it To IT")
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200P"
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200ops"
' WshNetwork.SetDefaultPrinter "\\atlantis\HP8000"
End If
' Wscript.Echo "Script is complete"
WScript.quit
-Monti
I am hoping someone could help me out with a vbscript. This is my first one and I am having trouble adding printers and mapped drives according to a users windows security group.
When I execute the script it will map the printers and drives for the first security group regardless if the user is a member or not then it will end.
Any advice is greatly appreciated.
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME:
'
' AUTHOR:
' DATE : 7/8/2004
'
' COMMENT: Test script
'
'==========================================================================
Option Explicit
Dim objNetwork, sysinfo, CurrentUser
Dim strGroups
Const it = "cn=tim it management"
Const adminstrative = "cn=tim administrative"
Const ops = "cn=tim ops managers"
Const exec = "cn=tim corp exec"
Const finance = "cn=tim finance"
Set objNetwork = CreateObject("WScript.Network")
' Forces script to skip errors (rem below line to see errors)
on error resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
' SET ALL DRIVES TO BE REMOVED HERE
WshNetwork.RemoveNetworkDrive "G:"
WshNetwork.RemoveNetworkDrive "N:"
WshNetwork.RemoveNetworkDrive "O:"
WshNetwork.RemoveNetworkDrive "R:"
' Set ALL NETWORK PRINTERS TO BE REMOVED HERE
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP laserjet 8000"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Color Laserjet 4550C"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Laserjet 2200 (Ops)"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP laserjet 2200 (Paul)"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\dc1a\HP Laserjet 4050"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP8000"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP4550"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP2200ops"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP2200P"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\chulak\HP4050"
' THIS LINE WILL RETRIEVE USERS AD INFO
Set sysinfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & sysinfo.UserName & "")
strGroups = LCase(Join(CurrentUser.MemberOf))
' SETTING ALL NETWORKDRIVES THAT ARE ASSIGNED TO ALL USERS
objNetwork.MapNetworkDrive "g:", "\\dc2a\g"
objNetwork.MapNetworkDrive "n:", "\\dc2a\n"
' objNetwork.MapNetworkDrive "z:", "\\servername\Users\" & objNetwork.UserName
' SETTING ALL PRINTERS ASSIGNED TO ALL USERS
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP8000"
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP4550"
' EXTRA PRINTERS FOR SPECIFIC SECURITY GROUP
If InStr(strGroups, administrative) Then
' WScript.Echo("Made it To administrative")
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.SetDefaultPrinter "\\atlantis\HP8000"
Elseif InStr(strGroups, finance) Then
' WScript.Echo("Made it To finance")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP4050"
' WshNetwork.SetDefaultPrinter "\\atlantis\HP4050"
Elseif InStr(strGroups, ops) Then
' WScript.Echo("Made it To OPs")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200ops"
WshNetwork.SetDefaultPrinter "\\atlantis\HP2200ops"
Elseif InStr(strGroups, exec) Then
' WScript.Echo("Made it To Corp Exec")
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
' WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200P"
Elseif InStr(strGroups, it) Then
WScript.Echo("made it To IT")
objNetwork.MapNetworkDrive "r:", "\\dc2a\r"
objNetwork.MapNetworkDrive "o:", "\\dc2a\o"
Set WshNetwork = WScript.CreateObject ("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200P"
WshNetwork.AddWindowsPrinterConnection "\\atlantis\HP2200ops"
' WshNetwork.SetDefaultPrinter "\\atlantis\HP8000"
End If
' Wscript.Echo "Script is complete"
WScript.quit
-Monti