Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: set "Managed By" tab in AD group

Reply
Thread Tools Display Modes

Re: set "Managed By" tab in AD group

 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-16-2009


"primoz88" <> wrote in message
news...
>
> Hi all,
>
>
>
> I am using a script posted in the other thread for Mass Group Creation
> in AD.
>
> The script is importing data from excel sheet (name,
> description,notes).
>
>
>
> Very important for me is to also organize the script to import
> ManagedBy information from the Excel sheet.
>
> I would like to put user name in another column, which will be
> automatically added to group "Managed By" tab.
>
>
>
> Can anyone advise how to generally update Group's "Managed By" tab?
>
> I will try to modify/implemt the code lateron to my script and I will
> post it?
>
>


The value assigned to the managedBy attribute must be the full Distinguished
Name of a user. An example might be similar to:

cn=Jim Smith,ou=Sales,ou=West,dc=MyDomain,dc=com

If you add the Distinguished Name to column 5 of the spreadsheet, you can
use this statement in the loop that reads rows of the spreadsheet:

strManagedBy = objSheet.Cells(intRow, 5).Value & ""

I append an empty string to the value in case there is no value in the cell
of the spreadsheet. All other values in the spreadsheet are required, but
this one is not (it can be blank). Then when values are assigned to the
attributes of the new group object, add these statements:

If (strManagedBy <> "") Then
objGroup.Put, "managedBy", strManagedBy
End If

Again, I account for the possibility that there is no value. An error is
raised if you attempt to assign either a blank or null. Finally, since the
script uses Option Explicit, you also need to add a statement near the
beginning to declare the new variable:

Dim strManagedBy

I hope this helps.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-19-2009

"primoz88" <> wrote in message
news...
>
> Hi to all,
>
> I am really a newbie in scripting and I am trying to modify the script
> I use for mass group creation. I was trying to modify it, adding the
> values "Richard Mueller [MVP]" suggested to me, but it did not work.
> Could you please have a look into the script I am using and try to
> modify it accordingly.
>
>
> =============================
> First sheet (Groups) in Excel file shows data in columns, as below:
> strNewGroup,strNewGroupLong,Description,Notes,Mana ged By
>
> Second Sheet (Param) shows:
> Domain DC=xxxx,DC=NET
> OU Grp OU=xxxx,OU=xxxx,OU=xxxx,OU=xxxx,OU=PMI,OU=xxxx
>
> So, what I would like to do is to organize the "ManagedBy" using my
> initial script.
> ==================
>
> The script is below:
> ==================
> Option Explicit
> ' On Error Resume Next
>
> Const cstExcelFilename = "Script_Group Creation.xls"
>
> Dim objWshShell, objFSO, objExcel, objOU, objGroup, objItem
> Dim strOU, strNewGroup, strNewGroupLong, strDomain, strOUGrp,
> strDescription, strNotes, strManagedBy
> Dim intIndex, bDebug
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objWshShell = CreateObject("WScript.Shell")
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = False
> bDebug = False
>
> ' Verify if exist Excel File
> If Not objFSO.FileExists(objWshShell.CurrentDirectory & "\" &
> cstExcelFilename) Then
> MsgBox "Missing Excel File: " & objWshShell.CurrentDirectory & "\" &
> cstExcelFilename
> WScript.Quit
> End If
>
> ' Open Excel File
> objExcel.Workbooks.Open objWshShell.CurrentDirectory & "\" &
> cstExcelFilename
>
> 'Select sheet Param
> objExcel.Sheets("Param").Select
>
> 'Domain
> strDomain = objExcel.Cells(1, 2)
>
> ' OU Grp
> strOUGrp = objExcel.Cells(2, 2)
>
> If bDebug Then
> WScript.Echo strDomain
> WScript.Echo strOUGrp
> End If
>
> 'Select sheet Users
> objExcel.Sheets("Groups").Select
>
> intIndex = 2
>
> While objExcel.Cells(intIndex, 1) <> ""
> strNewGroup = objExcel.Cells(intIndex, 1)
> strNewGroupLong = objExcel.Cells(intIndex, 2)
> strDescription = objExcel.Cells(intIndex, 3)
> strNotes = objExcel.Cells(intIndex, 4)
> strManagedBy = objExcel.Cells(intIndex, 5)
>
> If bDebug Then WScript.Echo strNewGroup & " , " & strNewGroupLong & " ,
> " & strDescription & " , " & strNotes & " , " & strManagedBy
>
> CreateGr strDomain, strOUGrp, strNewGroup, strNewGroupLong,
> strDescription, strNotes, strManagedBy
> intIndex = intIndex + 1
> Wend
>
> ' Close Excel File
> objExcel.Quit
>
>
> ' Cleaning
> Set objWshShell = Nothing
> Set objExcel = Nothing
> Set objFSO = Nothing
> Set objOU = Nothing
> WScript.Quit
>
> Sub CreateGr (strDomain, strOU, strNewGroup, strNewGroupLong,
> strDescription, strNotes, strManagedBy )
> Set objOU = GetObject("LDAP://" & strOU & "," & strDomain)
> Set objGroup = objOU.Create("Group", "cn=" & strNewGroupLong)
> objGroup.Put "sAMAccountName", strNewGroup
> objGroup.Put "Description", strDescription
> objGroup.Put "Info", strNotes
> objGroup.SetInfo
>
> End Sub
>
>
> --
> primoz88
> ------------------------------------------------------------------------
> primoz88's Profile: http://forums.techarena.in/members/143937.htm
> View this thread: http://forums.techarena.in/server-scripting/1259235.htm
>
> http://forums.techarena.in
>


The script looks good, but it does not assign the value strManagedBy to the
newly created groups. You need to add a line to Sub CreateGr to assign this
value. For example:

objGroup.Put "managedBy", strManagedBy

A minor point is that the script will be more efficient (faster) if you bind
the object reference objOU once in the main program, rather than repeatedly
in the Sub. You already declare objOU in the main program (in a Dim
statement), so it has global scope. Just move the "Set objOU" statement from
the Sub into the main program.

Even more minor is that the variables strOU snd objItem declared in the main
program are not used. The variable strOU in Sub CreateGr is a different
variable, whose value is assigned when you call the Sub.

Finally, you don't specify groupType, but that's probably fine. The default
if no value is assigned is a Global Security group.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-20-2009
I assume the new line got modified when you pasted it:

OBJGROUP.PUT \"MANAGEDBY\", STRMANAGEDBY

The error probably was raised on this line. Assuming the quotes are not
escaped with backslashes, the most probable cause is that the value assigned
to the variable strManagedBy is not a valid Distinguished Name. It must the
Distinguished Name (not the pre-Windows 2000 logon name) of a user.
Distinguished Names are in a form similar to:

cn=Jim Smith,ou=Sales,ou=Sales,dc=MyDomain,dc=com

You can use ADSI Edit or ldp.exe to view the Distinguished Names of objects
in AD. Or at the command prompt of a Domain Controller with Windows Server
2003 or above, run the following to retrieve the Distinguished Name of a
user with a given "pre-Windows 2000 logon name" (in this case "jsmith"):

dsquery user -samid jsmith

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
"primoz88" <> wrote in message
news...
>
> Dear Richard,
> I have managed to modify the script, but it still does not work. I have
> bolded lines I've added. Could you please have a look into and advise
> back? Even though, I have added the line "objGroup.Put "managedBy",
> strManagedBy", into Sub CreateGr, but I receive "a constraint violation
> occured" error 8007202F.
>
> Can you please have a look and help me out with it? Thanks a lot!
>
> script below:
> ======================
>
>> Option Explicit
>> ' On Error Resume Next
>>
>> Const cstExcelFilename = "Script_Group Creation.xls"
>>
>> Dim objWshShell, objFSO, objExcel, objOU, objGroup,
>> Dim strOU, strNewGroup, strNewGroupLong, strDomain, strOUGrp,
>> strDescription, strNotes, strManagedBy
>> Dim intIndex, bDebug
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objWshShell = CreateObject("WScript.Shell")
>> Set objExcel = CreateObject("Excel.Application")
>> objExcel.Visible = False
>> bDebug = False
>>
>> ' Verify if exist Excel File
>> If Not objFSO.FileExists(objWshShell.CurrentDirectory & "\" &
>> cstExcelFilename) Then
>> MsgBox "Missing Excel File: " & objWshShell.CurrentDirectory & "\" &
>> cstExcelFilename
>> WScript.Quit
>> End If
>>
>> ' Open Excel File
>> objExcel.Workbooks.Open objWshShell.CurrentDirectory & "\" &
>> cstExcelFilename
>>
>> 'Select sheet Param
>> objExcel.Sheets("Param").Select
>>
>> 'Domain
>> strDomain = objExcel.Cells(1, 2)
>>
>> ' OU Grp
>> strOUGrp = objExcel.Cells(2, 2)
>>
>> If bDebug Then
>> WScript.Echo strDomain
>> WScript.Echo strOUGrp
>> End If
>>
>> 'Select sheet Users
>> objExcel.Sheets("Groups").Select
>>
>> intIndex = 2
>>
>> While objExcel.Cells(intIndex, 1) <> ""
>> strNewGroup = objExcel.Cells(intIndex, 1)
>> strNewGroupLong = objExcel.Cells(intIndex, 2)
>> strDescription = objExcel.Cells(intIndex, 3)
>> strNotes = objExcel.Cells(intIndex, 4)
>> strManagedBy = objExcel.Cells(intIndex, 5)
>>
>> If bDebug Then WScript.Echo strNewGroup & " , " & strNewGroupLong & "

> ,
>> " & strDescription & " , " & strNotes & " , " & strManagedBy
>>
>> CreateGr strDomain, strOUGrp, strNewGroup, strNewGroupLong,
>> strDescription, strNotes, strManagedBy
>> intIndex = intIndex + 1
>> Wend
>>
>> ' Close Excel File
>> objExcel.Quit
>>
>> ' Cleaning
>> Set objWshShell = Nothing
>> Set objExcel = Nothing
>> Set objFSO = Nothing
>> Set objOU = Nothing
>> WScript.Quit
>>
>> Sub CreateGr (strDomain, strOU, strNewGroup, strNewGroupLong,
>> strDescription, strNotes, strManagedBy )
>> Set objOU = GetObject("LDAP://" & strOU & "," & strDomain)
>> Set objGroup = objOU.Create("Group", "cn=" & strNewGroupLong)
>> objGroup.Put "sAMAccountName", strNewGroup
>> objGroup.Put "Description", strDescription
>> objGroup.Put "Info", strNotes
>> OBJGROUP.PUT \"MANAGEDBY\", STRMANAGEDBY
>> objGroup.SetInfo
>>
>> End Sub

>
>
> --
> primoz88
> ------------------------------------------------------------------------
> primoz88's Profile: http://forums.techarena.in/members/143937.htm
> View this thread: http://forums.techarena.in/server-scripting/1259235.htm
>
> http://forums.techarena.in
>



 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-21-2009
Ah, your example is an ADsPath, which is close. You need to remove the
"LDAP://" part to make it a Distinguished Name. The value should be (one
line):

CN=Brown\,
John,OU=Non_Employees,OU=Users,OU=Krakow,OU=Produc tion,OU=Factory,OU=Users &
Workstations,DC=INTL,DC=NET

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"primoz88" <> wrote in message
news...
>
> Hello,
> I am receiving the error message at below line "objGroup.SetInfo".
>
> In Excel sheet, in column 5th "Managed By" I assume I have a proper
> Distinguished Name, which is:
> LDAP://CN=Brown\,
> John,OU=Non_Employees,OU=Users,OU=Krakow,OU=Produc tion,OU=Factory,OU=Users
> & Workstations,DC=INTL,DC=NET
>
> Should it be changed somehow?
> I am really hopeless about this "Managed By" field. This issue keeps me
> awake at night.
> Thanks
>
>
> --
> primoz88
> ------------------------------------------------------------------------
> primoz88's Profile: http://forums.techarena.in/members/143937.htm
> View this thread: http://forums.techarena.in/server-scripting/1259235.htm
>
> http://forums.techarena.in
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Windows Sidebar is managed by your system administrator on load" Niggle Windows Vista Administration 7 12-06-2007 11:07 AM
Kill IIS before upgrading!!!! (or "How I managed to upgrade XP to Vista on an Acer laptop") Jon Davis Windows Vista General Discussion 0 11-20-2006 02:27 PM
Kill IIS before upgrading!!!! (or "How I managed to upgrade XP to Vista on an Acer laptop") Jon Davis Windows Vista Installation 0 11-20-2006 02:27 PM
Re: Is the Computer object "Managed By" field informational or used for security Paul Bergson Active Directory 7 10-03-2006 08:06 AM
How to set page file to "System Managed size"? Ikira Kensuo Scripting 0 12-07-2005 09:37 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59