Mike Pratt
(Fresh Scripter)
2003-10-17 08:05 PM
Enumerating Computer Account Group Membership

I am trying to script network printer installation based upon the physical location a user logs on from...currently I am using DHCP reservations and scripting according to IP address and what group the user account is part of. What I'm trying to accomplish through KIX is to group my computer accounts and script the network printer according to what group the comptuer account is in.

Here's a snapshot of my KIX:

if INSTR("$groups","Nurses;") AND INSTR("$ipadd","10.1.1.201") OR INSTR("$ipadd","10.1.1.202") OR INSTR("$ipadd","10.1.1.203")
if ADDPRINTERCONNECTION ($pod1ptr) = 0 ? "Added printer connection...." endif
endif

Is it possible to script on computer account group membership?

Thanks!
Mike


tjcarst
(Hey THIS is FUN)
2003-10-17 08:29 PM
Re: Enumerating Computer Account Group Membership

Yes. See ComputerInGroup.udf http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000457

See also the last post in this thread for printers added based upon group membership http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920.

I have this working based upon variables because I have so many printers. It would be easier to do if you had fewer printers and could use ComputerInGroup.udf. Let me know if you want any more info on this, I am a beginner, so the experts here are a better source of help than me. I tend to need everything spelled out for me.

I also have one that works based upon a printsetup.ini file. All of my scripts have been obtained by code that exists here and tweaking done with the help of other here.

[ 17. October 2003, 20:35: Message edited by: tjcarst ]


tjcarst
(Hey THIS is FUN)
2003-10-17 08:40 PM
Re: Enumerating Computer Account Group Membership

Untested, but try this:

code:
call @scriptdir+'\computeringroup.udf'

if ComputerInGroup('nurses')=1 AND INSTR("$ipadd","10.1.1.201") OR INSTR("$ipadd","10.1.1.202") OR INSTR("$ipadd","10.1.1.203")

if ADDPRINTERCONNECTION ($pod1ptr) = 0 ? "Added printer connection...." endif

endif

tjcarst


Sealeopard
(KiX Master)
2003-10-17 08:44 PM
Re: Enumerating Computer Account Group Membership

See also TCP/IP Primer, Part I - IP Addresses .

Mike Pratt
(Fresh Scripter)
2003-10-17 08:52 PM
Re: Enumerating Computer Account Group Membership

Awesome! Thanks guys, I'll give that a try and I'll post results...

Mike Pratt
(Fresh Scripter)
2003-10-20 06:38 PM
Re: Enumerating Computer Account Group Membership

Hi guys,

I am just getting back to testing this and I think I need a hand with the syntax...I'm a newbie to KIX...

I've tried putting the UDF in a seperate file and also incorporating it in the KIX script - I haven't had luck with either. I would prefer to have it in a seperate *.udf file...

1. So if I had this code in computeringroup.udf:

Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction

2. I called upon the .udf with this code in my KIX script:

call @scriptdir+'\computeringroup.udf'

if ComputerInGroup("$groups","Bruns Pod 1;") AND INSTR("$ipadd","10.1.1.")
if ADDPRINTERCONNECTION ($ptrpod1) = 0 ? "Added printer connection...." endif
endif

3. I have put the computer account in the group called "Bruns Pod 1".

I know I'm missing syntax...could you help me out?

Thanks a million!
Mike


Sealeopard
(KiX Master)
2003-10-20 06:42 PM
Re: Enumerating Computer Account Group Membership

See the FAQ Forum under How to use UDFs and TCP/IP Primer, Part I - IP Addresses .

You should also check the ComputerInGroup() UDF header for correct syntax as I'm pretty sure yoru syntax is incorrect.

Also, please don't use vars inside strings.


Mike Pratt
(Fresh Scripter)
2003-10-21 08:44 PM
Re: Enumerating Computer Account Group Membership

I still haven't gotten this to work...I copied the syntax for the computeringroup.udf from here:

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000457

I have 4 printers in 4 different locations that I want to map, so it's not really that complex...I basically have 4 pods, and depending on what pod users logon to I want them to receive that pod's printer...I must be close, but I'm getting tripped up on the syntax...

I have the computeringroup.udf in my netlogon directory, but I'm not sure what to have in my main kix script for syntax...any help would be appreciated!

Thanks,
Mike


tjcarst
(Hey THIS is FUN)
2003-10-21 09:28 PM
Re: Enumerating Computer Account Group Membership

Don't modify the ComputerInGroup.udf

Since you only have 4 printers, it would be easiest to write the code for each printer. You may want to check to see if it is already mapped using PriMapState.udf and set it to default using SetDefaultPrinter.

I know there is a way to use an array so you don't have to create the script for each printer, but will have to research this, as I, too am a new Kixtart user.

Change your script to this:
code:
$prtpod1="\\server\share1"
$prtpod2="\\server\share2"
$prtpod3="\\server\share3"
$prtpod4="\\server\share4"

call @scriptdir+'\computeringroup.udf'

if ComputerInGroup('Bruns Pod')=1 AND INSTR("$ipadd","10.1.1.")
if not PriMapState($prtpod1)
? "Status " $prtpod1 " not connected"
? @serror
$nul=AddPrinterConnection(\\server\$prtpod1)
? "Status - Added printer connection "$prtpod1
? @serror
$nul=SetDefaultPrinter($prtpod1)
? "Status - Default printer set "$prtpod1
endif
endif

Edited to include proper syntax. Thanks Howard, missed that. [Embarrassed]

tjcarst

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


Sealeopard
(KiX Master)
2003-10-21 09:38 PM
Re: Enumerating Computer Account Group Membership

Read the TCP/IP Primer as the way you compare the IP Address will not work! UDFs are the way to go for IP address comparisons!

Howard Bullock
(KiX Supporter)
2003-10-21 09:38 PM
Re: Enumerating Computer Account Group Membership

Use proper quote syntax please:

$prtpod1=\\server\share1

shouls be:

$prtpod1="\\server\share1"


Sealeopard
(KiX Master)
2003-10-21 09:41 PM
Re: Enumerating Computer Account Group Membership

Oh, and the binary logic used in your very first post is incorrect as you don't properly separate the AND and OR blocks from each other. At least the binary logic will not achieve what you try to do.

tjcarst
(Hey THIS is FUN)
2003-10-21 09:47 PM
Re: Enumerating Computer Account Group Membership

Why are you even using the IP range if you are mapping based on groups? Put the pc's in the group and map on that condition. Do they move to different subnets and exist in different groups?

tjcarst


Sealeopard
(KiX Master)
2003-10-21 09:52 PM
Re: Enumerating Computer Account Group Membership

The IP address syntax could have location-based reasons as only the three specified computer should print to the particular printer and only if it is a nurse (and not a doctor). Might be a special-purpose printer.

tjcarst
(Hey THIS is FUN)
2003-10-21 10:24 PM
Re: Enumerating Computer Account Group Membership

Using IsInSubnet.udf http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000053

Try this:

code:
$ip=@IPADDRESS0
$networkid="10.1.1.0"
$subnetmask="255.255.255.0"
$answer=isinsubnet($ip,$networkid,$subnetmask)

$prtpod1="\\server\share1"
$prtpod2="\\server\share2"
$prtpod3="\\server\share3"
$prtpod4="\\server\share4"

call @scriptdir+'\computeringroup.udf'
call @scriptdir+'\isinsubnet.udf'

if ComputerInGroup('Bruns Pod')=1 AND IsInSubnet($answer)=1

if not PriMapState($prtpod1)
? "Status " $prtpod1 " not connected"
? @serror

$nul=AddPrinterConnection(\\server\$prtpod1)
? "Status - Added printer connection "$prtpod1
? @serror

$nul=SetDefaultPrinter($prtpod1)
? "Status - Default printer set "$prtpod1
? @serror

else exit 0

endif

endif

Edited to add call to isinsubnet.udf

tjcarst

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


Sealeopard
(KiX Master)
2003-10-21 10:38 PM
Re: Enumerating Computer Account Group Membership

code:
isinipsubnet("$answer")

is incorrect, just use the IsInSubnet call directly. And please don't use vars in strings (or quotes)!

[ 21. October 2003, 23:37: Message edited by: sealeopard ]


tjcarst
(Hey THIS is FUN)
2003-10-21 11:30 PM
Re: Enumerating Computer Account Group Membership

http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000053

At first I did have isinipsubnet, but this links shows isinsubnet.

I'll correct the syntax. Again. Sorry, I'm working on a million things and just thought I might be able to give Matt a little direction. It's apparent that I, too, am a newbie.


tjcarst
(Hey THIS is FUN)
2003-10-22 03:25 AM
Re: Enumerating Computer Account Group Membership

Download BinaryIP.udf and try this
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000030

Are you using a normal class a (255.0.0.0)10.0.0.0 subnet as a class C (255.255.255.0) network - 10.1.1.0/255.255.255.0?

code:
call @ScriptDir+'\BinaryIP.udf'
call @Scriptdir+'\ComputerInGroup.udf'

$prtpod1="\\server\share1"
$prtpod2="\\server\share2"
$prtpod3="\\server\share3"
$prtpod4="\\server\share4"

if ComputerInGroup('Bruns Pod')=1

if subnet("10.1.1.0", "10.1.1.0", "255.255.255.0") = 1

if not PriMapState($prtpod1)
? "Status " $prtpod1 " not connected"
? @serror

$nul=AddPrinterConnection(\\server\$prtpod1)
? "Status - Added printer connection "$prtpod1
? @serror

$nul=SetDefaultPrinter($prtpod1)
? "Status - Default printer set "$prtpod1
? @serror

endif

endif

endif



Sealeopard
(KiX Master)
2003-10-22 03:30 PM
Re: Enumerating Computer Account Group Membership

Now, what does the BinaryIP UDF have to do with the Subnet UDF as you don't include the Subnet UDF in your code?

Also, why do you jump back and forth between different UDFs, anyway? One time you use IsInSubnet(), another time you use BinaryIP(0/Subnet(). They both accomplish the same.


tjcarst
(Hey THIS is FUN)
2003-10-22 06:42 PM
Re: Enumerating Computer Account Group Membership

No idea. Just trying to get something to work for Mike. I don't know why I try though, I can't get anything to work for me. [Confused]

Edited to add that the link for subnet.udf says BinaryIP is a requirement.

tjcarst

[ 22. October 2003, 18:44: Message edited by: tjcarst ]


Mike Pratt
(Fresh Scripter)
2003-10-22 07:59 PM
Re: Enumerating Computer Account Group Membership

Hi guys,

I'm taking the IP address right out of the equation...I'm just going to create 4 groups, one for each pod...

I'm going to try TJ's suggestion...I'll let you know the results.. :-)

Thanks for all your help


Mike Pratt
(Fresh Scripter)
2003-10-22 08:26 PM
Re: Enumerating Computer Account Group Membership

Ok, this is what I have for syntax in my kix file:

$pod1ptr="\\server\Pod1"
$pod2ptr="\\server\Pod2"
$pod3ptr="\\server\POD3HPLJ"
$pod4ptr="\\server\HPLJ2100POD4"

call @scriptdir+'\computeringroup.udf'

if ComputerInGroup(Pod1)=1
$nul=AddPrinterConnection(\\server\$pod1ptr)
? "Status - Added printer connection "$pod1ptr
? @serror
$nul=SetDefaultPrinter($pod1ptr)
? "Status - Default printer set "$pod1ptr
endif

Here is the syntax I have in my computeringroup.udf...

Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction

I am getting an error that says:

error: invalid method/function call: missing ')'!
line: 58

Any ideas?


Sealeopard
(KiX Master)
2003-10-22 08:30 PM
Re: Enumerating Computer Account Group Membership

You're missing quotes all over the place! Please use proper quoting as explained in the KiXtart Manual. Strings MUST be enclosed within quotes and vars should not be used within quotes!

Mike Pratt
(Fresh Scripter)
2003-10-22 08:37 PM
Re: Enumerating Computer Account Group Membership

Guys! I got it!! Here is the script:

$pod1ptr="\\server\Pod1"
$pod2ptr="\\server\Pod2"
$pod3ptr="\\server\POD3HPLJ"
$pod4ptr="\\server\HPLJ2100POD4"

call @scriptdir+'\computeringroup.udf'

if ComputerInGroup('Pod1')=1
$nul=AddPrinterConnection($pod1ptr)
? "Status - Added printer connection "$pod1ptr
? @serror
$nul=SetDefaultPrinter($pod1ptr)
? "Status - Default printer set "$pod1ptr
endif

if ComputerInGroup('Pod2')=1
$nul=AddPrinterConnection($pod2ptr)
? "Status - Added printer connection "$pod2ptr
? @serror
$nul=SetDefaultPrinter($pod2ptr)
? "Status - Default printer set "$pod2ptr
endif

if ComputerInGroup('Pod3')=1
$nul=AddPrinterConnection($pod3ptr)
? "Status - Added printer connection "$pod3ptr
? @serror
$nul=SetDefaultPrinter($pod3ptr)
? "Status - Default printer set "$pod3ptr
endif

if ComputerInGroup('Pod4')=1
$nul=AddPrinterConnection($pod4ptr)
? "Status - Added printer connection "$pod4ptr
? @serror
$nul=SetDefaultPrinter($pod4ptr)
? "Status - Default printer set "$pod4ptr
endif

Thanks for all your help, this is going to save me a ton of time!


tjcarst
(Hey THIS is FUN)
2003-10-23 03:09 AM
Re: Enumerating Computer Account Group Membership

Congrats, Mike [Smile]

I'm happy you were able to get something to work for you!!

tjcarst


tjcarst
(Hey THIS is FUN)
2003-10-23 03:12 AM
Re: Enumerating Computer Account Group Membership

Also, if you did not want anything returned to the users, you could remove the lines that start with ? - this is informational only.

tjcarst


Sealeopard
(KiX Master)
2003-10-23 03:13 AM
Re: Enumerating Computer Account Group Membership

If the printer assignments are mutually exclusive, then a SELECT-CASE-ENDSELECT construct is more efficient.