whoam
asked on
Mapping Printers based on AD Sites
I am trying to map printers based on AD site. I'm using the following approach.
'+++++++BEGIN CREATING PRNTERS Per AD SITE++++++++++
Set objSysInfo = WScript.CreateObject("ADSy stemInfo")
Set objNetwork = WScript.CreateObject("Wscr ipt.Networ k")
strSiteName = objSysInfo.SiteName
Select Case strSiteName
Case "Site1" &_
net.AddWindowsPrinterConne ction "\\tb221002\PRMR", "MB_HP"
net.AddWindowsPrinterConne ction "\\tb221002\PBMB", "PBMB"
Case "Site2" &_
net.AddWindowsPrinterConne ction "\\tb052002\HP4200", "HP 4200"
net.AddWindowsPrinterConne ction "\\tb052002\HP4250", "HP 4250"
Case "Site3" &_
net.AddWindowsPrinterConne ction "\\tb022702\HP4250", "HP 4200"
'++++++++++++++++++++++END PRINTER MAPPING PER AD SITE++++++++++++++++++++++ ++++++++++ ++++
I'm getting an "Error 1024, Expected Statement"
at *here*
net.AddWindowsPrinterConne ction *here* "\\tb221002\PRMR", "MB_HP"
'+++++++BEGIN CREATING PRNTERS Per AD SITE++++++++++
Set objSysInfo = WScript.CreateObject("ADSy
Set objNetwork = WScript.CreateObject("Wscr
strSiteName = objSysInfo.SiteName
Select Case strSiteName
Case "Site1" &_
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
Case "Site2" &_
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
Case "Site3" &_
net.AddWindowsPrinterConne
'++++++++++++++++++++++END
I'm getting an "Error 1024, Expected Statement"
at *here*
net.AddWindowsPrinterConne
ASKER
It works fine if I do an IF THEN based on AD group memebership, it's just when I pull the method into the select case.
ASKER
I think each Case line may need a new line after it, i.le. the &_ may be the problem. I'll try it tomorrow.
ASKER
Also need and
End Select
statement I'm guessing
End Select
statement I'm guessing
ASKER
You're correct... the syntax for Case is:
Select Case <Variant>
Case "<Value1>"
' Statements
Case "<Value2>"
' Statements
End Select
The ampersand (&) is used for concatenation and the Underscore (_) is used to tell the script processer that the statement is continued on the next line (useful to make things look neater).
Chris
There are a lot of problems with that script.
-You are referencing variables that don't exist:
NET.addwindowsprinterconne ction
<should be>
OBJNETWORK.addwindowsprint erconnecti on
Make "Option Explicit" the first line in the script so that you can't script for a non-declared variable
-The second parameter for AddWindowsPrinterConnectio n is a Driver name, not the display name for the printer.
You don't need to specify anything but the UNC for the printer share for this function:
OBJNETWORK.AddWindowsPrint erConnecti on "\\tb221002\PRMR", "MB_HP"
<should be>
OBJNETWORK.AddWindowsPrint erConnecti on "\\tb221002\PRMR"
-As mentioned above you need "End Select" at the end of the "Select Case" statement
-As mentioned above you don't need the &_ after the Case statements
-You should lower or upper your comparisons to make sure you don't miss a site install due to capital or lowercase differences in letters'
All together now....
'Start Script
Option Explicit
Dim objSysInfo, ObjNetwork
Set objSysInfo = WScript.CreateObject("ADSy stemInfo")
Set objNetwork = WScript.CreateObject("Wscr ipt.Networ k")
Select Case UCASE(objSysInfo.SiteName)
Case "SITE1"
objNetwork.AddWindowsPrint erConnecti on "\\tb221002\PRMR"
objNetwork.AddWindowsPrint erConnecti on "\\tb221002\PBMB"
Case "SITE2"
objNetwork.AddWindowsPrint erConnecti on "\\tb052002\HP4200"
objNetwork.AddWindowsPrint erConnecti on "\\tb052002\HP4250"
Case "SITE3"
objNetwork.AddWindowsPrint erConnecti on "\\tb022702\HP4250"
Case else
msgbox "no printers were added"
End Select
'End Script
You will problably find these two things usefull also:
Sub RemoveAllNetPrinters
dim WSHNet
dim clprinters, i
Set WSHNet= WScript.CreateObject("Wscr ipt.Networ k")
Set clPrinters = WshNetwork.EnumPrinterConn ections
On Error Resume Next
For i = 0 to clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnec tion clPrinters.Item(i+1), true
Next
End Sub
Set a default printer AFTER you add a printer:
objNetwork.AddWindowsPrint erConnecti on "\\tb221002\PRMR"
objNetwork.AddWindowsPrint erConnecti on "\\tb221002\PBMB"
objNetwork.SetDefaultPrint er "\\tb221002\PRMR"
If you want to get real fancy you could actually assign printers based on:
-OU location (user or computer)
-User group membership
-Computer group membership
-Indexed container attributes
Good Luck....
-You are referencing variables that don't exist:
NET.addwindowsprinterconne
<should be>
OBJNETWORK.addwindowsprint
Make "Option Explicit" the first line in the script so that you can't script for a non-declared variable
-The second parameter for AddWindowsPrinterConnectio
You don't need to specify anything but the UNC for the printer share for this function:
OBJNETWORK.AddWindowsPrint
<should be>
OBJNETWORK.AddWindowsPrint
-As mentioned above you need "End Select" at the end of the "Select Case" statement
-As mentioned above you don't need the &_ after the Case statements
-You should lower or upper your comparisons to make sure you don't miss a site install due to capital or lowercase differences in letters'
All together now....
'Start Script
Option Explicit
Dim objSysInfo, ObjNetwork
Set objSysInfo = WScript.CreateObject("ADSy
Set objNetwork = WScript.CreateObject("Wscr
Select Case UCASE(objSysInfo.SiteName)
Case "SITE1"
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
Case "SITE2"
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
Case "SITE3"
objNetwork.AddWindowsPrint
Case else
msgbox "no printers were added"
End Select
'End Script
You will problably find these two things usefull also:
Sub RemoveAllNetPrinters
dim WSHNet
dim clprinters, i
Set WSHNet= WScript.CreateObject("Wscr
Set clPrinters = WshNetwork.EnumPrinterConn
On Error Resume Next
For i = 0 to clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnec
Next
End Sub
Set a default printer AFTER you add a printer:
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.SetDefaultPrint
If you want to get real fancy you could actually assign printers based on:
-OU location (user or computer)
-User group membership
-Computer group membership
-Indexed container attributes
Good Luck....
ASKER
Sorry, what I show is a small snip from the whole script. I missed the DIM lines. While I haven't had time to test the answers I was wondering if there was a way to assign a friendly name to a printer added via a UNC. I had thought I could do it after the UNC as above, but I guess not.
You would set that info on the print server, in my environment we use descriptions like:
Main Copier Room (Color)
Main Copier Room (B & W)
It's the first field in the properties pages of the printer (on the server) just above the location field. Microsoft didn't put a field name next to that property like the rest, how odd for them to be inconsistent.....
Main Copier Room (Color)
Main Copier Room (B & W)
It's the first field in the properties pages of the printer (on the server) just above the location field. Microsoft didn't put a field name next to that property like the rest, how odd for them to be inconsistent.....
ASKER
I get an error 800A03f6, Expeted 'End" at the beginning of the else case line
Set objSysInfo = WScript.CreateObject("ADSy stemInfo")
Set objNetwork = WScript.CreateObject("Wscr ipt.Networ k")
strSiteName = objSysInfo.SiteName
Select Case strSiteName
Case "Beach"
net.AddWindowsPrinterConne ction "\\tb221002\MyeHP", "MB_HP"
net.AddWindowsPrinterConne ction "\\tb221002\PBMB", "PBMB"
Case "ville"
net.AddWindowsPrinterConne ction "\\tb052002\HP4200", " HP 4200"
net.AddWindowsPrinterConne ction "\\tb052002\HP4250", " HP 4250"
Case "West"
net.AddWindowsPrinterConne ction "\\tb022702\HP4250", " HP 4200"
Else Case
MsgBox "No site detected"
End Select
Set objSysInfo = WScript.CreateObject("ADSy
Set objNetwork = WScript.CreateObject("Wscr
strSiteName = objSysInfo.SiteName
Select Case strSiteName
Case "Beach"
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
Case "ville"
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
Case "West"
net.AddWindowsPrinterConne
Else Case
MsgBox "No site detected"
End Select
ASKER
Alright, stupid post, should be 'Case Else'
still working on it.
still working on it.
ASKER
I get an error code Code 800A01A8 - Object required
when i try to use your print remove subroutine
looks like ...
Sub RemoveAllNetPrinters
dim WSHNet
dim clprinters, i
Set WSHNet= WScript.CreateObject("Wscr ipt.Networ k")
Set clPrinters = WshNetwork.EnumPrinterConn ections
*the above line should read...*
Set clPrinters = WSHNet.creatobject("Wscrip t.network" )
On Error Resume Next
For i = 0 to clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnec tion clPrinters.Item(i+1), true
Next
End Sub
when i try to use your print remove subroutine
looks like ...
Sub RemoveAllNetPrinters
dim WSHNet
dim clprinters, i
Set WSHNet= WScript.CreateObject("Wscr
Set clPrinters = WshNetwork.EnumPrinterConn
*the above line should read...*
Set clPrinters = WSHNet.creatobject("Wscrip
On Error Resume Next
For i = 0 to clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnec
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So the enumPrinterConnections method will only address network printers?
As for the driver parameters, I thought I had gotten rid of them, but I guess not, will do that next.
The problem with this is there are so many ways to do things, that while I'm fixing one problem, I think of a new way to do something else. It's fun, but I wish I was better at it. Maybe after a few more months.
As for the driver parameters, I thought I had gotten rid of them, but I guess not, will do that next.
The problem with this is there are so many ways to do things, that while I'm fixing one problem, I think of a new way to do something else. It's fun, but I wish I was better at it. Maybe after a few more months.
ASKER
If work isnt' too busy tomorrow I should have time to finish this.
Yep, local printers are not affected by that sub.
I must encourage you to spend as much time with this stuff as possible, it will reduce the amount of work you have to do in the long run. I started with WSCRIPT and went on to do VB6 and now I'm starting VB.Net. I administer a school system where each student has their own logon (2000+ students); in the past 3 years I haven't created a single account. I made an application that gets info from a district student database to create accounts, the teachers use this to create all the student accounts on the fly, literally a single click operation. The app creates the user folder, assigns group memberships, logon scripts and even NTFS permissions. The groups are tied to scripts and other apps/scripts that assign network drives, printers, and even access to deploying/running other applications. After the accounts are created teachers can change student passwords and lock/unlock accounts when necessary, leaving our small IT department free to tinker with more complex issues. Keep hacking away at it, automation is a very sweet thing...
I must encourage you to spend as much time with this stuff as possible, it will reduce the amount of work you have to do in the long run. I started with WSCRIPT and went on to do VB6 and now I'm starting VB.Net. I administer a school system where each student has their own logon (2000+ students); in the past 3 years I haven't created a single account. I made an application that gets info from a district student database to create accounts, the teachers use this to create all the student accounts on the fly, literally a single click operation. The app creates the user folder, assigns group memberships, logon scripts and even NTFS permissions. The groups are tied to scripts and other apps/scripts that assign network drives, printers, and even access to deploying/running other applications. After the accounts are created teachers can change student passwords and lock/unlock accounts when necessary, leaving our small IT department free to tinker with more complex issues. Keep hacking away at it, automation is a very sweet thing...
ASKER
I know I'm dragging my feet on the points, but I can't determine if this part work until I get the whole script working. If you wouldn't mind looking at
https://www.experts-exchange.com/questions/21830526/Using-OU-membership-to-assign-drives-or-other-resources.html
Then I should be good.
Thanks
https://www.experts-exchange.com/questions/21830526/Using-OU-membership-to-assign-drives-or-other-resources.html
Then I should be good.
Thanks
ASKER
Okay, I took what you gave me and put it all together. We are close but just not there yet. If you could, follow to
https://www.experts-exchange.com/questions/21831914/AD-VBasic-Login-Script-Long.html
https://www.experts-exchange.com/questions/21831914/AD-VBasic-Login-Script-Long.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/999614b9-1d1e-4d7a-af43-e22ab22fb782.asp