Page 3 of 4 <1234>
Topic Options
#46715 - 2003-10-23 01:19 PM Re: Create AD Global Groups for printer objects
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I have looked at this UDF several times and can not see anything I did incorrectly. That said, I hope someone finds a small proggie error so that this can be concluded for everyone wanting to use this UDF. But I am going to write this up in Perl today to see if the behavior is different.

[ 23. October 2003, 13:20: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46716 - 2003-10-23 02:00 PM Re: Create AD Global Groups for printer objects
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Howard, think we might have it ... you have a typo in your function prototype:

Function CreateADGroup ($Container, $GrpName, $GrpType, $SecurityEnabled, optional $Description, optional $sSAMAcctName)

specifically this parm:

$sSAMAcctName

think you have an extra "s" at the beginning, ja ?

Top
#46717 - 2003-10-23 02:28 PM Re: Create AD Global Groups for printer objects
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Thank you very much Shawn. The extra set of eyes was definitely needed.

Tested with the example code and ALL groups are properly created.

With the invalid $SamAccountName variable each group was trying to set the same SamAccountName "Null" which must be unique. I will immediatley correct this in the UDF Library.

Thank again!. [Big Grin]

[edit]
This makes me feel a little sheepish. [Embarrassed]
[/edit]

[ 23. October 2003, 14:43: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46718 - 2003-10-23 02:49 PM Re: Create AD Global Groups for printer objects
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What makes you feel a little sheepish - making a simple typo and not being able to see it ? We have all been there before my brother.
Top
#46719 - 2003-10-23 05:04 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Hallelujah! Hallelujah! Halleluuuuuuuujah!

Sorry, I'm not even a religious person, but this warranted something. [Smile]

The original script worked. Very slick, very cool. Thanks for the effort, it truly is appreciated. (Even though I could have manually created these groups three times over, I am thrilled to get this to work!!)

Now I have another project I'll be pestering you with related to these groups.

Thanks everyone!

Script used:

code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920

call @ScriptDir+'\CreateAdGroup.udf'

;********** Beginning of group creation *********

$logfile=c:\printers5.txt
$printers = GetObject("LDAP://OU=Printers,DC=madonna,DC=local")
$DN_of_OU ="OU=Printer Groups,DC=madonna,DC=local"

if @error
? @error - @serror
else

$rc=redirectoutput($logfile,1)

for each $printer in $printers
$printername = $printer.name
$printername = substr($printername,4)

if left($printername,7) = "MRH-01-"

$printername = lcase(substr($printername,8))

$defprintgroup = "D_MRH-01_"+$printername

if CreateAdGroup($DN_of_OU, $defprintgroup, "global", 1, "Default Printer")
? "Group " + $defprintgroup + " successfully created"
else
? "CreateAdGroup " + $defprintgroup + " Failed with Error: " + @error
endif

$addlprintgroup = "A_MRH-01_"+$printername

if CreateAdGroup($DN_of_OU, $addlprintgroup, "global", 1, "Additional Printer")
? "Group " + $addlprintgroup + " successfully created"
else
? "CreateAdGroup " + $addlprintgroup + " Failed with Error: " + @error
endif

endif

next

$rc=redirectoutput('')

endif

tjcarst

[edited to clean up code spacing a little]

[ 23. October 2003, 17:15: Message edited by: tjcarst ]

Top
#46720 - 2003-10-23 05:10 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Now I'll use this script to check for the existence of the workstations in the newly created printer groups and install the printers if needed. So cool.

code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920

call @ScriptDir+'\PriMapState.udf'

;********** Prevent script from running on a server or Win95*********
if @userid = administrator
call @Scriptdir+'\osid.udf'
$os=osid()
if $os[1]='Win95' or $os[2]<>'Workstation'
exit 0
endif
endif

;********** Prevent script from running on Medrec pcs *********
if InGroup ("Medrec Group")
exit 0
endif

;********** Beginning of printer mapping *********
$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")

if @error
? @serror
else

for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add and set default printer ---

if left($GrpName,2) = "D_"
$defprinter = substr($GrpName,3)
$defprinter = join(split($defprinter,"_"),"\")

if not PriMapState("\\" + $defprinter)
? "Status - Printer not connected \\"+$defprinter
$nul=AddPrinterConnection("\\" + $defprinter)
? "Status - Printer added \\"+ $defprinter
? @serror

$nul=SetDefaultPrinter("\\" + $defprinter)
"Status - Default Printer set \\" +$defprinter
? @serror

endif

if PriMapState("\\" + $defprinter)<>2
$nul=SetDefaultPrinter("\\" + $defprinter)
? "Status - Default Printer set \\" + $defprinter
? @serror

endif

endif

;--- Add additional printers ---

if left($GrpName,2) = "A_"
$addlprinter = substr($GrpName,3)
$addlprinter = join(split($addlprinter,"_"),"\")

if not PriMapState("\\" + $addlprinter)
? "Status - Printer not connected \\" + $addlprinter
$S=AddPrinterConnection("\\" + $addlprinter)
? "Status - Printer added \\" + $addlprinter
? @serror
?
endif

endif

next

endif

tjcarst [Big Grin]

[ 23. October 2003, 17:12: Message edited by: tjcarst ]

Top
#46721 - 2003-10-23 05:22 PM Re: Create AD Global Groups for printer objects
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Sorry that you lost so much time, but I am happy that you now have working code and a greater understanding KiXtart.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46722 - 2003-10-23 05:23 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
One small flaw. The group names that are longer than 15 characters fail for the mappings. I know it was indicated in the createad.udf that SAM account names could only contain 15 characters, but if I go into AD and find the longer names, I can modify the Pre-Windows 2000 name to be longer. Then the mappings occur correctly. Even stranger is that I am using XP and it should be using the AD name, not the SAM name.

I don't have many long group names, so this will take no time at all to fix the names in AD.

Top
#46723 - 2003-10-23 05:25 PM Re: Create AD Global Groups for printer objects
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Please see the FAQ Forum under Limits in NetBIOS, computer/printer names, share names/comments
_________________________
There are two types of vessels, submarines and targets.

Top
#46724 - 2003-10-23 05:28 PM Re: Create AD Global Groups for printer objects
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
A lesson for us all. If SETOPTION ("Explicit","ON") was used, this problem would have been seen at the first execution of the script. We all should be using SETOPTION ("Explicit","ON") in ALL of our code to help prevent such problems.

[ 23. October 2003, 17:29: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46725 - 2003-10-23 05:34 PM Re: Create AD Global Groups for printer objects
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
code:
    If Len($SAMAcctName) > 20
; "SamAccountName CANNOT be bigger than 20 characters"
$SAMAcctName = left($SAMAcctName, 20)
;WriteLog2($LogFile, "Function: CreateADGroup - Trimming SAMAcctName to 20 characters")
? "Function: CreateADGroup - Trimming SAMAcctName to 20 characters"
EndIf

Even in NT4, you can make group names longer than 20 characters with code, but the supporting interface in User Manager can not process them. The tool has the limitation not the under lying data store. So you have to be cautious to build your names to the least common denominator for everything to work.

quote:

sAMAccountName
Required. Specify a string that is the name used to support clients and servers from a previous version of Windows®. Note that the sAMAccountName should be less than 20 characters to support clients from a previous version of Windows.
The sAMAccountName must be unique among all security principal objects within the domain. You should perform a query against the domain to verify that the sAMAccountName is unique within the domain.



[ 23. October 2003, 18:52: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46726 - 2003-10-23 05:58 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Thanks, Howard.

One last question on this topic for me:

I am using a bit of code that checks to see if the default printer is set (after adding printers). I want it to set the default printer if it isn't correctly set, but already installed - wrong printer set default. If it is not mapped, it does correctly add and set as default.

I am using PriMapstate.udf for this and thought that it used to work, but I must have changed something.

Any idea what I have wrong with this bit?

code:
if PriMapState("\\" + $defprinter)<>2
$nul=SetDefaultPrinter("\\" + $defprinter)
? "Status - Default Printer set \\" + $defprinter
? @serror
endif


Top
#46727 - 2003-10-23 06:01 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Thanks also for the explanation on th 15 character and 20 character limits. I am no longer using User Manager as I am in Native Mode AD. This should not be an issue.

tjcarst

Top
#46728 - 2003-10-23 08:38 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Well, I'm not sure it's the correct way to check for the status of the default printer (if already mapped buy not default), but this seems to work. Get the status of PriMapState and if not equal to 2, SetDefaultPrinter.

code:
;if PriMapState("\\" + $defprinter)<>2 ;does not work

$x=$PriMapstate
if $x<>2
$nul=SetDefaultPrinter("\\" + $defprinter)
? "Status - Default Printer set \\" + $defprinter
? @serror
endif

tjcarst

[ 23. October 2003, 20:40: Message edited by: tjcarst ]

Top
#46729 - 2003-10-23 08:45 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Posted too soon. It sets the default printer EVERY time now.
Top
#46730 - 2003-10-23 08:53 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I still don't have it. I have verified that the value returned is in fact 2, but can't get it to change the default printer if already installed.

code:
$rc=PriMapState("\\" + $defprinter)
? $rc
;if $rc=<>2
if $rc<>2

$nul=SetDefaultPrinter("\\" + $defprinter)
? "Status - Default Printer set \\" + $defprinter
? @serror ?
else
exit 0
endif

tjcarst
[edited to fix =<>]

[ 23. October 2003, 21:09: Message edited by: tjcarst ]

Top
#46731 - 2003-10-23 08:56 PM Re: Create AD Global Groups for printer objects
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
quote:
$rc=<>2
Now, that is an interesting construct that I haven't yet seen [Confused]
_________________________
There are two types of vessels, submarines and targets.

Top
#46732 - 2003-10-23 09:08 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Yep. Caught that. Sorry I didn't update here.

Still doesn't work, but shows my own inability to make up my mind [Smile]

Top
#46733 - 2003-10-23 09:10 PM Re: Create AD Global Groups for printer objects
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Was this a training session, or is it trying to compete with the Golf series for the most posts on one subject? [Razz]
Top
#46734 - 2003-10-23 09:15 PM Re: Create AD Global Groups for printer objects
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Training session. Review my posts. I'm struggling. But persistent. I am going to get this to work. (Most likely not without help)

[Frown]

[ 23. October 2003, 21:16: Message edited by: tjcarst ]

Top
Page 3 of 4 <1234>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org