![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Adding a user to groups via dsadd HI all. I'm trying to modify an HTA that I have to list user groups for a user, and get it to add another user to each of those groups. Here's what I've got so far: Code: <HTML>
<HEAD>
<TITLE>Users Group Migration HTA</TITLE>
<HTA:APPLICATION
ID="MyApp"
APPLICATIONNAME="Template"
BORDER="thick"
BORDERSTYLE="complex"
CAPTION="yes"
CONTEXTMENU="no"
ICON="http://Your URL/your icon.ico"
INNERBORDER="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
NAVIGABLE="no"
SCROLL="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="maximized"/>
</HEAD>
<SCRIPT Language="VBScript">
Sub Window_onLoad
window.resizeTo 640, 480
End Sub
Sub ExitProgram
window.close()
End Sub
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
set WshNetwork = CreateObject("Wscript.Network")
strUserName1 = WshNetwork.UserName
strUserDomain = WshNetwork.UserDomain
' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "Suddenlink"
Sub btnRun_Click
sUser1 = User1.value
sUser2 = User2.value
' Set sDomain = objNetwork.UserDomain
set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
set objUser2 = GetObject("WinNT://" & strUserDomain & "/" & sUser2)
for each oGroup in objUser.Groups
sGroups = sGroups & oGroup.Name & vbcrlf & "<br>"
dsadd user objuser2 -memberof oGroup
Next
DataArea.InnerHTML = sGroups
End Sub
</SCRIPT>
<body STYLE="font:10pt arial; color:white;
(background-color:Menu;
color:MenuText;
cursor:default;)">
<p align=left><b>Group Migration Tool</b></font></p>
<table>
<tr>
<col align="left"></col>
<col width="160"></col>
<col align="left"></col>
<th><b>New User ID.</b></th>
<th> </th>
<th><b>Template User ID.</b></th>
</tr>
<tr>
<td><input type="text" name="User1" size=20><p align=left></td>
<td> </td>
<td><input type="text" name="User2" size=20><p align=left></td>
</tr>
</table>
<tr>
<td><input type="button" value="Run" name="btnRun"
onClick="btnRun_Click" STyle='background-color: ButtonFace;'
STyle='color:ButtonText;'></td>
<td><input id=runbutton type="button" value="Cancel"
onClick="ExitProgram" STyle='background-color: ButtonFace;'
STyle='color:ButtonText;'></td>
</tr>
<p>
<Span ID = "DataArea"></Span>
</body>
</html>
includes my dsadd, but I'm not sure how I would terminate the line. Does anyone have any ideas? Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Adding a user to groups via dsadd "MattW" <winberrym@xxxxxx> wrote in message news:053cc53c-5130-4bb4-908e-ab40ca45f040@xxxxxx Quote: > HI all. I'm trying to modify an HTA that I have to list user groups > for a user, and get it to add another user to each of those groups. > Here's what I've got so far: > > Code: > <HTML>
> <HEAD>
> <TITLE>Users Group Migration HTA</TITLE>
> <HTA:APPLICATION
> ID="MyApp"
> APPLICATIONNAME="Template"
> BORDER="thick"
> BORDERSTYLE="complex"
> CAPTION="yes"
> CONTEXTMENU="no"
> ICON="http://Your URL/your icon.ico"
> INNERBORDER="yes"
> MAXIMIZEBUTTON="yes"
> MINIMIZEBUTTON="yes"
> NAVIGABLE="no"
> SCROLL="no"
> SHOWINTASKBAR="yes"
> SINGLEINSTANCE="yes"
> SYSMENU="yes"
> VERSION="1.0"
> WINDOWSTATE="maximized"/>
> </HEAD>
>
> <SCRIPT Language="VBScript">
>
> Sub Window_onLoad
> window.resizeTo 640, 480
> End Sub
>
> Sub ExitProgram
> window.close()
> End Sub
>
> ' Constants for the NameTranslate object.
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
>
> set WshNetwork = CreateObject("Wscript.Network")
> strUserName1 = WshNetwork.UserName
> strUserDomain = WshNetwork.UserDomain
>
> ' Specify the NetBIOS name of the domain.
> strNetBIOSDomain = "Suddenlink"
>
> Sub btnRun_Click
>
> sUser1 = User1.value
> sUser2 = User2.value
> ' Set sDomain = objNetwork.UserDomain
> set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
> set objUser2 = GetObject("WinNT://" & strUserDomain & "/" & sUser2)
>
> for each oGroup in objUser.Groups
> sGroups = sGroups & oGroup.Name & vbcrlf & "<br>"
> dsadd user objuser2 -memberof oGroup
> Next
> DataArea.InnerHTML = sGroups
> End Sub
> </SCRIPT>
> <body STYLE="font:10pt arial; color:white;
> (background-color:Menu;
> color:MenuText;
> cursor:default;)">
> <p align=left><b>Group Migration Tool</b></font></p>
> <table>
> <tr>
> <col align="left"></col>
> <col width="160"></col>
> <col align="left"></col>
> <th><b>New User ID.</b></th>
> <th> </th>
> <th><b>Template User ID.</b></th>
> </tr>
> <tr>
> <td><input type="text" name="User1" size=20><p align=left></td>
> <td> </td>
> <td><input type="text" name="User2" size=20><p align=left></td>
> </tr>
> </table>
> <tr>
> <td><input type="button" value="Run" name="btnRun"
> onClick="btnRun_Click" STyle='background-color: ButtonFace;'
> STyle='color:ButtonText;'></td>
> <td><input id=runbutton type="button" value="Cancel"
> onClick="ExitProgram" STyle='background-color: ButtonFace;'
> STyle='color:ButtonText;'></td>
> </tr>
> <p>
> <Span ID = "DataArea"></Span>
> </body>
> </html>
>
> I'm getting an expected end of statement error on the line that > includes my dsadd, but I'm not sure how I would terminate the line. > Does anyone have any ideas? Thanks! use the Add method of the group to add members. You can also use the IsMember method of the group object to check if the user is already a member. For example, replace this (not tested): =========== for each oGroup in objUser.Groups sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" dsadd user objuser2 -memberof oGroup Next ======= With this: ========= for each oGroup in objUser.Groups sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" ' Check if user already a member. If (oGroup.IsMember(objUser2.AdsPath) = False) Then ' Add the user to the group. oGroup.Add(objUser2.AdsPath) End If Next -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Adding a user to groups via dsadd On Jun 4, 10:55*am, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > "MattW" <winber...@xxxxxx> wrote in message > > news:053cc53c-5130-4bb4-908e-ab40ca45f040@xxxxxx > > > > > Quote: > > HI all. *I'm trying to modify an HTA that I have to list user groups > > for a user, and get it to add another user to each of those groups. > > Here's what I've got so far: Quote: > > Code: > > <HTML> > > <HEAD> > > <TITLE>Users Group Migration HTA</TITLE> > > <HTA:APPLICATION > > *ID="MyApp" > > APPLICATIONNAME="Template" > > BORDER="thick" > > BORDERSTYLE="complex" > > CAPTION="yes" > > CONTEXTMENU="no" > > ICON="http://YourURL/your icon.ico" > > INNERBORDER="yes" > > MAXIMIZEBUTTON="yes" > > MINIMIZEBUTTON="yes" > > NAVIGABLE="no" > > SCROLL="no" > > SHOWINTASKBAR="yes" > > SINGLEINSTANCE="yes" > > SYSMENU="yes" > > VERSION="1.0" > > WINDOWSTATE="maximized"/> > > </HEAD> Code: > Quote: > > I'm getting an expected end of statement error on the line that > > includes my dsadd, but I'm not sure how I would terminate the line. > > Does anyone have any ideas? *Thanks! > The command line utility dsadd is not a VBScript method. However, you can > use the Add method of the group to add members. You can also use the > IsMember method of the group object to check if the user is already a > member. For example, replace this (not tested): > =========== > for each oGroup in objUser.Groups > * * sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > * * dsadd user objuser2 -memberof oGroup > Next > ======= > With this: > ========= > for each oGroup in objUser.Groups > * * sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > * * ' Check if user already a member. > * * If (oGroup.IsMember(objUser2.AdsPath) = False) Then > * * * * ' Add the user to the group. > * * * * oGroup.Add(objUser2.AdsPath) > * * End If > Next > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > --- Hide quoted text - > > - Show quoted text - thread and used that, came back to post about it. It works like a champ. Thanks! |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Adding a user to groups via dsadd On Jun 4, 10:55*am, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > "MattW" <winber...@xxxxxx> wrote in message > > news:053cc53c-5130-4bb4-908e-ab40ca45f040@xxxxxx > > > > > Quote: > > HI all. *I'm trying to modify an HTA that I have to list user groups > > for a user, and get it to add another user to each of those groups. > > Here's what I've got so far: Quote: > > Code: > > <HTML> > > <HEAD> > > <TITLE>Users Group Migration HTA</TITLE> > > <HTA:APPLICATION > > *ID="MyApp" > > APPLICATIONNAME="Template" > > BORDER="thick" > > BORDERSTYLE="complex" > > CAPTION="yes" > > CONTEXTMENU="no" > > ICON="http://YourURL/your icon.ico" > > INNERBORDER="yes" > > MAXIMIZEBUTTON="yes" > > MINIMIZEBUTTON="yes" > > NAVIGABLE="no" > > SCROLL="no" > > SHOWINTASKBAR="yes" > > SINGLEINSTANCE="yes" > > SYSMENU="yes" > > VERSION="1.0" > > WINDOWSTATE="maximized"/> > > </HEAD> Code: > Quote: > > I'm getting an expected end of statement error on the line that > > includes my dsadd, but I'm not sure how I would terminate the line. > > Does anyone have any ideas? *Thanks! > The command line utility dsadd is not a VBScript method. However, you can > use the Add method of the group to add members. You can also use the > IsMember method of the group object to check if the user is already a > member. For example, replace this (not tested): > =========== > for each oGroup in objUser.Groups > * * sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > * * dsadd user objuser2 -memberof oGroup > Next > ======= > With this: > ========= > for each oGroup in objUser.Groups > * * sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > * * ' Check if user already a member. > * * If (oGroup.IsMember(objUser2.AdsPath) = False) Then > * * * * ' Add the user to the group. > * * * * oGroup.Add(objUser2.AdsPath) > * * End If > Next > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > --- Hide quoted text - > > - Show quoted text - be done in an HTA using the dsget and dsadd utilities? I like the fact that the VBScript is rock solid, but I'm attracted by the piped one liner possibilies. Powershell was an early contender, but I had to rule it out, and I still had hope for the ds utilities. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Adding a user to groups via dsadd "MattW" <winberrym@xxxxxx> wrote in message news:6434da77-02b5-47b8-b6f3-8a3d15781446@xxxxxx On Jun 4, 10:55 am, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > "MattW" <winber...@xxxxxx> wrote in message > > news:053cc53c-5130-4bb4-908e-ab40ca45f040@xxxxxx > > > > > Quote: > > HI all. I'm trying to modify an HTA that I have to list user groups > > for a user, and get it to add another user to each of those groups. > > Here's what I've got so far: Quote: > > Code: > > <HTML> > > <HEAD> > > <TITLE>Users Group Migration HTA</TITLE> > > <HTA:APPLICATION > > ID="MyApp" > > APPLICATIONNAME="Template" > > BORDER="thick" > > BORDERSTYLE="complex" > > CAPTION="yes" > > CONTEXTMENU="no" > > ICON="http://YourURL/your icon.ico" > > INNERBORDER="yes" > > MAXIMIZEBUTTON="yes" > > MINIMIZEBUTTON="yes" > > NAVIGABLE="no" > > SCROLL="no" > > SHOWINTASKBAR="yes" > > SINGLEINSTANCE="yes" > > SYSMENU="yes" > > VERSION="1.0" > > WINDOWSTATE="maximized"/> > > </HEAD> Code: > Quote: > > I'm getting an expected end of statement error on the line that > > includes my dsadd, but I'm not sure how I would terminate the line. > > Does anyone have any ideas? Thanks! > The command line utility dsadd is not a VBScript method. However, you can > use the Add method of the group to add members. You can also use the > IsMember method of the group object to check if the user is already a > member. For example, replace this (not tested): > =========== > for each oGroup in objUser.Groups > sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > dsadd user objuser2 -memberof oGroup > Next > ======= > With this: > ========= > for each oGroup in objUser.Groups > sGroups = sGroups & oGroup.Name & vbcrlf & "<br>" > ' Check if user already a member. > If (oGroup.IsMember(objUser2.AdsPath) = False) Then > ' Add the user to the group. > oGroup.Add(objUser2.AdsPath) > End If > Next > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > --- Hide quoted text - > > - Show quoted text - be done in an HTA using the dsget and dsadd utilities? I like the fact that the VBScript is rock solid, but I'm attracted by the piped one liner possibilies. Powershell was an early contender, but I had to rule it out, and I still had hope for the ds utilities. --------- The dsadd utility creates new objects in AD, rather than modifying existing ones. I think you could use dsmod to add members to a group. For example, to add user "cn=Jim Smith" to group "cn=Test Group" the command could be: dsmod group "cn=Test Group,ou=West,dc=MyDomain,dc=com" -addmbr "cn=Jim Smith,ou=West,dc=MyDomain,dc=com" To add user2 to all groups that user1 belongs to, the command could be similar to (one line): dsget user "cn=User1,ou=West,dc=MyDomain,dc=com" -memberOf | dsmod group -addmbr "cn=User2,ou=West,dc=MyDomain,dc=com" although I have not tested. These are command line tools. I don't know how to run them from an HTA, but in VBScript you could use the Run method of the wshShell object. I would assign the command to a variable and use %comspec% /c to run the command. For example in VBScript: ======== Set objShell = CreateObject("Wscript.Shell") strCmd = "%comspec% /c dsget user ""cn=User1,ou=West,dc=MyDomain,dc=com"" -memberOf " _ & "| dsmod group -addmbr ""cn=User2,ou=West,dc=MyDomain,dc=com""" Wscript.Echo strCmd objShell.Run strCmd, 2 ======= Note the quotes in the string must be doubled and I break up the command into two concatenated strings to avoid line wrapping and make it easier to read. I added the Wscript.Echo statement for troubleshooting, so at a command console you can make sure the command looks correct (and does not raise syntax errors due to mismatched quotes). If User2 is already a member of any of the groups, I assume an error is raised. I don't think that situation can be handled using command line tools (unless the error is ignored). -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| AD: Looking for user not in a groups | PowerShell | |||
| Crash When Trying Adding A News Groups | Vista mail | |||
| Problem with adding new contacts & groups | Vista mail | |||
| User Groups in Vista | Vista account administration | |||
| Error adding news groups | Vista mail | |||