Hi all, i have the following script that i have tried to piece
sections from two scripts together, my overall aim is to have the
local machine that this script is run on, added to the group specified
in objGroup....

and i deperate for help - not sure what i'm doing wrong....

many thanks in advance
Jason

--------------------------------------------------------------------------------------------------------------------------------------------
' Constants required for name translate
Const ADS_PROPERTY_APPEND = 3
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

'Get the NETBIOS name of the domain
Set objSystemInfo = CreateObject("ADSystemInfo")
Set objGroup = GetObject ("LDAP://cn=Adobe Reader 8,ou=software
distribution,ou=distribution groups,ou=********,dc=********,dc=local")

strDomain = objSystemInfo.DomainShortName

' Get the name of the computer
set objNetwork = createobject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Call function to return the distinguished name (DN) of the computer
strComputerDN = getComputerDN(strComputer,strDomain)

function getComputerDN(byval strComputer,byval strDomain)
' Function to get the distinguished name of a computer
' from the NETBIOS name of the computer (strcomputer)
' and the NETBIOS name of the domain (strDomain) using
' name translate

Set objTrans = CreateObject("NameTranslate")
' Initialize name translate using global catalog
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Input computer name (NT Format)
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"
' Get Distinguished Name.
getComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

end Function

'MsgBox strComputerDN

objGroup.PutEx ADS_PROPERTY_APPEND, "member", strComputerDN

objGroup.SetInfo

-------------------------------------------------------------------------------------------------------------------------------------------

Re: Scripting Groups by Richard

Richard
Thu Jul 26 08:30:32 CDT 2007


<wills.jason@gmail.com> wrote in message
news:1185437556.792502.38020@w3g2000hsg.googlegroups.com...
> Hi all, i have the following script that i have tried to piece
> sections from two scripts together, my overall aim is to have the
> local machine that this script is run on, added to the group specified
> in objGroup....
>
> and i deperate for help - not sure what i'm doing wrong....
>
> many thanks in advance
> Jason
>
> --------------------------------------------------------------------------------------------------------------------------------------------
> ' Constants required for name translate
> Const ADS_PROPERTY_APPEND = 3
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
> 'Get the NETBIOS name of the domain
> Set objSystemInfo = CreateObject("ADSystemInfo")
> Set objGroup = GetObject ("LDAP://cn=Adobe Reader 8,ou=software
> distribution,ou=distribution groups,ou=********,dc=********,dc=local")
>
> strDomain = objSystemInfo.DomainShortName
>
> ' Get the name of the computer
> set objNetwork = createobject("Wscript.Network")
> strComputer = objNetwork.ComputerName
>
> ' Call function to return the distinguished name (DN) of the computer
> strComputerDN = getComputerDN(strComputer,strDomain)
>
> function getComputerDN(byval strComputer,byval strDomain)
> ' Function to get the distinguished name of a computer
> ' from the NETBIOS name of the computer (strcomputer)
> ' and the NETBIOS name of the domain (strDomain) using
> ' name translate
>
> Set objTrans = CreateObject("NameTranslate")
> ' Initialize name translate using global catalog
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> ' Input computer name (NT Format)
> objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"
> ' Get Distinguished Name.
> getComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
>
> end Function
>
> 'MsgBox strComputerDN
>
> objGroup.PutEx ADS_PROPERTY_APPEND, "member", strComputerDN
>
> objGroup.SetInfo
>
> -------------------------------------------------------------------------------------------------------------------------------------------
>

The error message should have indicated that it was raised on the line:

objGroup.PutEx ADS_PROPERTY_APPEND, "member", strComputerDN

The PutEx method requires an Array for the last parameter, even if there is
only one value. This should be:

objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array(strComputerDN)

That should fix the error. Other points. Instead of using NameTranslate to
convert the NetBIOS name of the current computer you can retrieve the DN
directly from the ADSystemInfo object. For example:

strComputerDN = objSystemInfo.ComputerName

This saves a lot of the code and is more efficient. Finally, I prefer to use
the Add method of the group object to add members. I would replace the
objGroup.PutEx statement with:

objGroup.Add("LDAP://" & strComputerDN)

Then there is also no need for the objGroup.SetInfo statement.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Scripting Groups by wills

wills
Thu Jul 26 14:08:43 CDT 2007

On 26 Jul, 14:30, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> <wills.ja...@gmail.com> wrote in message
>
> news:1185437556.792502.38020@w3g2000hsg.googlegroups.com...
>
>
>
>
>
> > Hi all, i have the following script that i have tried to piece
> > sections from two scripts together, my overall aim is to have the
> > local machine that this script is run on, added to the group specified
> > in objGroup....
>
> > and i deperate for help - not sure what i'm doing wrong....
>
> > many thanks in advance
> > Jason
>
> > -----------------------------------------------------------------------=
----=AD-----------------------------------------------------------------
> > ' Constants required for name translate
> > Const ADS_PROPERTY_APPEND =3D 3
> > Const ADS_NAME_INITTYPE_GC =3D 3
> > Const ADS_NAME_TYPE_NT4 =3D 3
> > Const ADS_NAME_TYPE_1779 =3D 1
>
> > 'Get the NETBIOS name of the domain
> > Set objSystemInfo =3D CreateObject("ADSystemInfo")
> > Set objGroup =3D GetObject ("LDAP://cn=3DAdobe Reader 8,ou=3Dsoftware
> > distribution,ou=3Ddistribution groups,ou=3D********,dc=3D********,dc=3D=
local")
>
> > strDomain =3D objSystemInfo.DomainShortName
>
> > ' Get the name of the computer
> > set objNetwork =3D createobject("Wscript.Network")
> > strComputer =3D objNetwork.ComputerName
>
> > ' Call function to return the distinguished name (DN) of the computer
> > strComputerDN =3D getComputerDN(strComputer,strDomain)
>
> > function getComputerDN(byval strComputer,byval strDomain)
> > ' Function to get the distinguished name of a computer
> > ' from the NETBIOS name of the computer (strcomputer)
> > ' and the NETBIOS name of the domain (strDomain) using
> > ' name translate
>
> > Set objTrans =3D CreateObject("NameTranslate")
> > ' Initialize name translate using global catalog
> > objTrans.Init ADS_NAME_INITTYPE_GC, ""
> > ' Input computer name (NT Format)
> > objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"
> > ' Get Distinguished Name.
> > getComputerDN =3D objTrans.Get(ADS_NAME_TYPE_1779)
>
> > end Function
>
> > 'MsgBox strComputerDN
>
> > objGroup.PutEx ADS_PROPERTY_APPEND, "member", strComputerDN
>
> > objGroup.SetInfo
>
> > -----------------------------------------------------------------------=
----=AD----------------------------------------------------------------
>
> The error message should have indicated that it was raised on the line:
>
> objGroup.PutEx ADS_PROPERTY_APPEND, "member", strComputerDN
>
> The PutEx method requires an Array for the last parameter, even if there =
is
> only one value. This should be:
>
> objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array(strComputerDN)
>
> That should fix the error. Other points. Instead of using NameTranslate to
> convert the NetBIOS name of the current computer you can retrieve the DN
> directly from the ADSystemInfo object. For example:
>
> strComputerDN =3D objSystemInfo.ComputerName
>
> This saves a lot of the code and is more efficient. Finally, I prefer to =
use
> the Add method of the group object to add members. I would replace the
> objGroup.PutEx statement with:
>
> objGroup.Add("LDAP://" & strComputerDN)
>
> Then there is also no need for the objGroup.SetInfo statement.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -

Richard - you're a genius,

and don't take this in the wrong way, but i love you - i'm still
learning vbscript, and the simpler i can make it the better, managed
to reduce to around 6 lines of code - i like it!!

Many thanks for your help.

Jason