<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Вывод групп из AD]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11166&amp;type=atom" />
	<updated>2015-12-25T08:57:09Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11166</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99915#p99915" />
			<content type="html"><![CDATA[<p><strong>shade45</strong><br />Странная манера задавать вопрос и даже не пробовать использовать данный ответ.<br />Вот взял твой скрипт, поудалял все лишнее и применил все, данные выше, советы </p><div class="codebox"><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=content-type content=&quot;text-html; charset=utf-8&quot;&gt;
&lt;meta http-equiv=MSThemeCompatible content=yes&gt;
&lt;hta:application /&gt;
&lt;/head&gt;
&lt;script type=&quot;text/vbscript&quot;&gt;
	Sub MemberGroupOf()
		StrDomName = Trim(GetObject(&quot;LDAP://RootDSE&quot;).Get(&quot;DefaultNamingContext&quot;))
		StrSQL = &quot;Select ADsPath From &#039;LDAP://&quot; &amp; StrDomName &amp; &quot;&#039; Where ObjectCategory = &#039;User&#039; AND SAMAccountName = &#039;&quot; &amp; idUser.Value &amp; &quot;&#039;&quot;
		Set ObjConn = CreateObject(&quot;ADODB.Connection&quot;)
		ObjConn.Provider = &quot;ADsDSOObject&quot;:  ObjConn.Open &quot;Active Directory Provider&quot;
		Set ObjRS = CreateObject(&quot;ADODB.Recordset&quot;)
		ObjRS.Open StrSQL, ObjConn
		If Not ObjRS.EOF Then
			ObjRS.MoveLast: ObjRS.MoveFirst
			Set ObjUser = GetObject(Trim(ObjRS.Fields(&quot;ADsPath&quot;).Value))
			Set GroupCollection = ObjUser.Groups
			For Each ObjGroup In GroupCollection
				DataArea.insertAdjacentHTML &quot;BeforeEnd&quot;, ObjGroup.CN &amp; &quot;&lt;br&gt;&quot;
				CheckForNestedGroup ObjGroup
			Next
			Set ObjGroup = Nothing: Set GroupCollection = Nothing:  Set ObjUser = Nothing
		Else
			alert &quot;Couldn&#039;t find user &quot; &amp; idUser.Value &amp; &quot; in AD.&quot;
		End If
		ObjRS.Close:    Set ObjRS = Nothing
		ObjConn.Close:  Set ObjConn = Nothing
	End Sub

	Sub CheckForNestedGroup(ObjThisGroupNestingCheck)
		On Error Resume Next
		AllMembersCollection = ObjThisGroupNestingCheck.GetEx(&quot;MemberOf&quot;)
		For Each StrMember In AllMembersCollection
			If StrMember &lt;&gt; &quot;&quot; Then
				StrADsPath = &quot;LDAP://&quot; &amp; StrMember
				Set ObjThisIsNestedGroup = GetObject(StrADsPath)
				If InStr(GroupsList, ObjThisIsNestedGroup.CN) = 0 Then
					DataArea.insertAdjacentHTML &quot;BeforeEnd&quot;, &quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot; &amp; ObjThisIsNestedGroup.CN &amp; &quot;&lt;br&gt;&quot;
				End If
				CheckForNestedGroup ObjThisIsNestedGroup
			End If
		Next
		Set ObjThisIsNestedGroup = Nothing: Set StrMember = Nothing:    Set AllMembersCollection = Nothing
	End Sub
&lt;/script&gt;
&lt;body&gt;
Пользователь: &lt;input type=&quot;text&quot; id=&quot;idUser&quot;&gt;
&lt;input type=&quot;button&quot; onclick=&quot;MemberGroupOf()&quot; value=&quot;Является членом групп&quot;&gt;
&lt;div id=&quot;DataArea&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></div><p>Что непонятно?</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-25T08:57:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99915#p99915</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99913#p99913" />
			<content type="html"><![CDATA[<p>пробовал не помогло, это добавлял чтобы посмотреть как она отрабатывает, про то что я выше писал, она пишет первые несколько групп, потом стирает и поверх пишет другие.</p><p>Оригинальный код:<br /><a href="http://stackoverflow.com/questions/26116292/vbscript-retrieving-a-users-nested-groups-and-getting-rid-of-repetitions">http://stackoverflow.com/questions/2611 … epetitions</a></p>]]></content>
			<author>
				<name><![CDATA[shade45]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33296</uri>
			</author>
			<updated>2015-12-25T08:05:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99913#p99913</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99910#p99910" />
			<content type="html"><![CDATA[<p><strong>Flasher</strong>, согласен.<br />А еще лучше не формировать strHtml, а писать сразу в DataArea.</p><div class="codebox"><pre><code>DataArea.insertAdjacentHTML &quot;BeforeEnd&quot;, ObjGroup.CN &amp; &quot;&lt;br&gt;&quot; </code></pre></div>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-25T07:41:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99910#p99910</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99908#p99908" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>			strHtml = GroupsList
			DataArea.innerHTML = strHtml
		Next</code></pre></div><p>на<br /></p><div class="codebox"><pre><code>		Next
		DataArea.innerHTML = GroupsList</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Flasher]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27593</uri>
			</author>
			<updated>2015-12-25T06:56:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99908#p99908</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99907#p99907" />
			<content type="html"><![CDATA[<p><strong>mozers</strong> если закомментировать 34 строчку, тогда отобразить только &quot;внешние&quot; группы, вложенные не появяться. Странно, почему он поверх то пишет, если я вывожу в .txt, то все хорошо проходит с помощью добавления:<br /></p><div class="codebox"><pre><code>  Writing list in a file named Groups &lt;username&gt;.txt
    Set WriteFile = WScript.CreateObject(&quot;WScript.Shell&quot;)
        Dim fso, f
        Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
       Set f = fso.OpenTextFile(&quot;Groups &quot; &amp; StrUserName &amp; &quot;.txt&quot;, ForWriting,true)
        f.write(GroupsList)
        f.Close </code></pre></div>]]></content>
			<author>
				<name><![CDATA[shade45]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33296</uri>
			</author>
			<updated>2015-12-25T04:59:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99907#p99907</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99899#p99899" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>shade45 пишет:</cite><blockquote><p>код конечно хорош, но у меня завис(, он собирает в себя всех пользователей домена</p></blockquote></div><p>Это - точно. Чтоб брал только с конкретного OU надо в 97 строке вместо strDomName вставить LDAP string вашего OU. Типа так:</p><div class="codebox"><pre><code>Set oOU = GetObject (&quot;LDAP://OU=Users,OU=city,DC=firma,DC=ru&quot;)</code></pre></div><p>А твоя hta-шка у меня отработала без ошибок, но у нас вложенные группы не практикуются, так что <strong>Flasher</strong> сделал верное предположение.</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-24T10:44:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99899#p99899</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99898#p99898" />
			<content type="html"><![CDATA[<p>А если закомментить 34 строку?</p>]]></content>
			<author>
				<name><![CDATA[Flasher]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27593</uri>
			</author>
			<updated>2015-12-24T09:30:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99898#p99898</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99896#p99896" />
			<content type="html"><![CDATA[<p><strong>mozers</strong> Ваш код конечно хорош, но у меня завис(, он собирает в себя всех пользователей домена</p><p>Полный код для проверки, там с помощью msgbox видно как он работает, показывает половину шесть из 10 значений нормально, потом стирает все, пишет 7, 8 значения, потом все стирает и пишет сверху 9 и 10 значения только<br /></p><div class="codebox"><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=content-type content=&quot;text-html; charset=utf-8&quot;&gt;
&lt;meta http-equiv=MSThemeCompatible content=yes&gt;
&lt;hta:application
	id=&quot;HTAApp&quot;
 /&gt;
 &lt;/head&gt;
 &lt;script type=&quot;text/vbscript&quot;&gt;
 
Sub MemberGroupOf
		Const ForReading = 1, ForWriting = 2, ForAppend = 8
		Dim ObjUser, ObjRootDSE, ObjConn, ObjRS
		Dim GroupCollection, ObjGroup,StrUserName, StrDomName, StrSQL
		Dim GroupsList,WriteFile
		GroupsList = &quot;&quot;
		Set ObjRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
		StrDomName = Trim(ObjRootDSE.Get(&quot;DefaultNamingContext&quot;))
		Set ObjRootDSE = Nothing
		StrUserName = InputBox(&quot;Enter user login&quot;, &quot;Info needed&quot;, &quot;&quot;)
		&#039;StrUserName = &quot;GilmullinRR&quot; &#039;ВВЕДИТЕ ЛОГИН для ПОИСКА
		StrSQL = &quot;Select ADsPath From &#039;LDAP://&quot; &amp; StrDomName &amp; &quot;&#039; Where ObjectCategory = &#039;User&#039; AND SAMAccountName = &#039;&quot; &amp; StrUserName &amp; &quot;&#039;&quot;
		Set ObjConn = CreateObject(&quot;ADODB.Connection&quot;)
		ObjConn.Provider = &quot;ADsDSOObject&quot;:  ObjConn.Open &quot;Active Directory Provider&quot;
		Set ObjRS = CreateObject(&quot;ADODB.Recordset&quot;)
		ObjRS.Open StrSQL, ObjConn
		If Not ObjRS.EOF Then
			ObjRS.MoveLast: ObjRS.MoveFirst
			Set ObjUser = GetObject (Trim(ObjRS.Fields(&quot;ADsPath&quot;).Value))
			Set GroupCollection = ObjUser.Groups
			&#039;strHtml = &quot;Looking for groups &quot; &amp; StrUserName &amp; &quot; is member of. This may take some time...&quot;
			For Each ObjGroup In GroupCollection
				GroupsList = GroupsList &amp; VbCrLf &amp; &quot;&lt;br&gt;&quot; &amp; ObjGroup.CN 
				CheckForNestedGroup ObjGroup
			Next
			
			Set ObjGroup = Nothing: Set GroupCollection = Nothing:  Set ObjUser = Nothing
			strHtml = strHtml &amp; GroupsList
		Else
			strHtml = &quot;Couldn&#039;t find user &quot; &amp; StrUserName &amp; &quot; in AD.&quot;
		End If
		ObjRS.Close:    Set ObjRS = Nothing
		ObjConn.Close:  Set ObjConn = Nothing
		DataArea.innerHTML = strHtml
	end sub

	Sub CheckForNestedGroup(ObjThisGroupNestingCheck)
		On Error Resume Next
		Dim AllMembersCollection, StrMember, StrADsPath, ObjThisIsNestedGroup, TabAdd, i 
		AllMembersCollection = ObjThisGroupNestingCheck.GetEx(&quot;MemberOf&quot;)
		For Each StrMember in AllMembersCollection
			If StrMember &lt;&gt; &quot;&quot; Then
				StrADsPath = &quot;LDAP://&quot; &amp; StrMember
				Set ObjThisIsNestedGroup = GetObject(StrADsPath)
				If InStr(GroupsList, ObjThisIsNestedGroup.CN) = 0 Then &#039;(Uncomment this If and indent lines below to remove groups already in the list)
				&#039;TabAdd = &quot;&quot;
				For i = 0 to Recurcount
					TabAdd = TabAdd &amp; vbTab
				Next
				&#039;GroupsList = GroupsList &amp; TabAdd &amp; &quot; &quot; &amp; ObjThisIsNestedGroup.CN &amp; VbCrLf
				GroupsList = GroupsList &amp; ObjThisIsNestedGroup.CN &amp; VbCrLf
				End If
				msgbox GroupsList
				
				
				&#039;Recursion to include nested groups of nested groups
				Recurcount = Recurcount + 1
				CheckForNestedGroup ObjThisIsNestedGroup
				Recurcount = Recurcount - 1
			End If
			
			
			strHtml = GroupsList
			DataArea.innerHTML = strHtml
			
		Next
		Set ObjThisIsNestedGroup = Nothing: Set StrMember = Nothing:    Set AllMembersCollection = Nothing
End Sub



&lt;/script&gt;
&lt;body&gt;
&lt;input type=&quot;button&quot; id=&quot;MemberGroupOf1&quot; onclick=&quot;MemberGroupOf()&quot; value=&quot;MemberGroupOf&quot;&gt;
	&lt;div class=&quot;right_col&quot;&gt;
		&lt;span id = &quot;DataArea&quot; name=&quot;value&quot;&gt;нажмите.&lt;/span&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></div><p>1 картинка - как выводит в .hta<br /><a href="http://radikal.ru/fp/e3dc4689c8584420998c9a99a35eca1b"><span class="postimg"><img src="http://s020.radikal.ru/i701/1512/c4/10ed9bb5be45t.jpg" alt="http://s020.radikal.ru/i701/1512/c4/10ed9bb5be45t.jpg" /></span></a><br />1 картинка - как выводит в .vbs - msgbox<br /><a href="http://radikal.ru/fp/cda9d49c80be45c5a7cfa645b2f42fbe"><span class="postimg"><img src="http://s014.radikal.ru/i328/1512/4e/7d347b8a22c6t.jpg" alt="http://s014.radikal.ru/i328/1512/4e/7d347b8a22c6t.jpg" /></span></a></p>]]></content>
			<author>
				<name><![CDATA[shade45]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33296</uri>
			</author>
			<updated>2015-12-24T03:26:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99896#p99896</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99886#p99886" />
			<content type="html"><![CDATA[<p>2<strong>shade45</strong><br />Извини, чой то лень искать ошибку в том обрубке кода который ты привел.<br />Лучше я приведу свой рабочий вариант, только &quot;region&quot; в 3х местах замени на имя своего домена.<br />Если понравилось, то могу прислать 2ю половину кода (в ней - показ и удаление NTFS прав юзера на конкретные каталоги).<br /></p><div class="codebox"><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=content-type content=&quot;text-html; charset=utf-8&quot;&gt;
&lt;meta http-equiv=MSThemeCompatible content=yes&gt;
&lt;hta:application
	id=&quot;HTAApp&quot;
	applicationName=&quot;Удаление прав пользователя&quot;
	icon=&quot;UserAccountControlSettings.exe&quot;
	maximizeButton=&quot;no&quot;
	innerBorder=&quot;no&quot;
	selection=&quot;no&quot;
	contextMenu=&quot;no&quot;
	singleinstance=&quot;yes&quot;
	version=&quot;3.6&quot;
 /&gt;
&lt;style type=&quot;text/css&quot;&gt;
	body, table {background-color:threedface;}
	body, input, table, legend {font-family:MS Shell Dlg; font-size:8pt;}
	legend, label {color:highlight;}
	legend {font-weight:bold;}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	window.resizeTo(410, 260);
	document.title = HTAApp.applicationName + &#039; v.&#039; + HTAApp.version;
	function CheckGroupName(name){
		return /^psn/i.test(name) ? &quot;checked&quot; : &quot;disabled&quot;;
	}
	function SetHeight(){
		var height = idTable.scrollHeight;
		window.resizeTo(410, (height&lt;800)?(height+40):800);
	}
	function ClearUsersList(){
		while (idUsers.firstChild) idUsers.removeChild(idUsers.firstChild);
		idUsers.add(document.createElement(&quot;OPTION&quot;));
		idGroupsList.innerHTML = &quot;&quot;;
		idFoldersList.innerHTML = &quot;&quot;;
	}
	function idUsersOnchange(){
		GetUserGroups();
		GetFoldersRights();
		SetHeight();
	}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload=&quot;CreateUsersList()&quot; style=&quot;margin:0px;&quot;&gt;
&lt;table id=&quot;idTable&quot; width=&quot;100%&quot; cellpadding=&quot;2&quot; cellspacing=&quot;4&quot;&gt;
	&lt;tr&gt;
		&lt;td align=&quot;center&quot;&gt;
			&lt;select id=&quot;idUsers&quot; onchange=&quot;idUsersOnchange()&quot; style=&quot;width:100%&quot;&gt;&lt;/select&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;
			&lt;fieldset&gt;&lt;legend&gt;&amp;nbsp;Опции поиска пользователей:&amp;nbsp;&lt;/legend&gt;
				&lt;input id=&quot;idFindRecursive&quot; type=&quot;checkbox&quot; checked onclick=&quot;CreateUsersList()&quot; hidefocus&gt;&lt;label for=&quot;idFindRecursive&quot;&gt;поиск во вложенных контейнерах&lt;/label&gt;&lt;br&gt;
				&lt;input id=&quot;idFindLock&quot; type=&quot;checkbox&quot; checked onclick=&quot;CreateUsersList()&quot; hidefocus&gt;&lt;label for=&quot;idFindLock&quot;&gt;выводить заблокированных пользователей&lt;/label&gt;
			&lt;/fieldset&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr height=&quot;100%&quot;&gt;
		&lt;td valign=&quot;top&quot;&gt;
			&lt;table width=&quot;100%&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot;&gt;
				&lt;tr&gt;
					&lt;td&gt;
						&lt;fieldset&gt;&lt;legend&gt;&amp;nbsp;Является членом групп:&amp;nbsp;&lt;/legend&gt;
							&lt;div id=&quot;idGroupsList&quot;&gt;&lt;/div&gt;
						&lt;/fieldset&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td align=&quot;center&quot; valign=&quot;top&quot; height=&quot;40px&quot;&gt;
						&lt;input type=&quot;button&quot; value=&quot;Удалить из отмеченных групп&quot; onclick=&quot;RemoveFromGroups()&quot; style=&quot;color:red&quot; hidefocus&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td valign=&quot;top&quot;&gt;
						&lt;fieldset&gt;&lt;legend&gt;&amp;nbsp;Имеет индивидуальный доступ к каталогам:&amp;nbsp;&lt;/legend&gt;
							&lt;div id=&quot;idFoldersList&quot;&gt;&lt;/div&gt;
						&lt;/fieldset&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td align=&quot;center&quot;&gt;
						&lt;input type=&quot;button&quot; value=&quot;Удалить доступ к отмеченным каталогам&quot; onclick=&quot;RemoveFromFolders()&quot; style=&quot;color:red&quot; hidefocus&gt;
					&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/table&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;script type=&quot;text/vbscript&quot;&gt;
Sub CreateUsersList()
	ClearUsersList
	Set ObjRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
	strDomName = ObjRootDSE.Get(&quot;DefaultNamingContext&quot;)
	Set oOU = GetObject (&quot;LDAP://&quot; &amp; strDomName)
	EnumObjWithContainer oOU
End Sub

Sub EnumObjWithContainer(oContainer)
	For Each oADO in oContainer
		Select Case oADO.Class
			Case &quot;user&quot;
				Set oOption = document.createElement(&quot;OPTION&quot;)
				oOption.text=oADO.cn
				oOption.value=oADO.sAMAccountName
				If oADO.AccountDisabled And idFindLock.checked Then
					oOption.style.color=&quot;red&quot;
					idUsers.add(oOption)
				Else
					idUsers.add(oOption)
				End If
			Case &quot;organizationalUnit&quot;
				if idFindRecursive.checked Then EnumObjWithContainer oADO
		End Select 
	Next 
End Sub

Sub GetUserGroups()
	idGroupsList.innerHTML = &quot;&quot;
	username = idUsers.options(idUsers.selectedIndex).value
	Set oUser = GetObject(&quot;WinNT://region/&quot; &amp; username &amp; &quot;,user&quot;)
	For Each oGroup In oUser.Groups
		If LCase(oGroup.Class) = &quot;group&quot; Then
			chk = CheckGroupName(oGroup.Name)
			idGroupsList.insertAdjacentHTML &quot;BeforeEnd&quot;, &quot;&lt;input id=idGroups type=checkbox &quot; &amp; chk &amp; &quot; value=&quot;&quot;&quot; &amp; oGroup.Name &amp; &quot;&quot;&quot; hidefocus&gt;&quot; &amp; oGroup.Name &amp; &quot;&lt;br&gt;&quot;
		End If
	Next
	idUsers.focus
End Sub

Sub RemoveFromGroups()
	username = idUsers.options(idUsers.selectedIndex).value
	Set oUser = GetObject(&quot;WinNT://region/&quot; &amp; username &amp; &quot;,user&quot;)
	For Each group In document.getElementsByName(&quot;idGroups&quot;)
		If group.checked Then
			Set oGroup = GetObject(&quot;WinNT://region/&quot; &amp; group.value &amp; &quot;,group&quot;)
			oGroup.Remove(oUser.ADsPath)
		End If
	Next
	GetUserGroups
End Sub

&lt;/script&gt;
&lt;/html&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-23T08:40:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99886#p99886</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Вывод групп из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99851#p99851" />
			<content type="html"><![CDATA[<p>Здравствуйте, подскажите пожалуйста, есть код, который показывает в какие группы входит данный пользователь. Показывает Nested Group, но почему когда я его добавляю в приложение на .hta, скрипт больше не показывает Nested Group (т.е. вместо 10 записей выводит всего 3). Можете подсказать как решить данную проблемку?</p><p>.hta<br /></p><div class="codebox"><pre><code>Sub MemberGroupOf
		Const ForReading = 1, ForWriting = 2, ForAppend = 8
		Dim ObjUser, ObjRootDSE, ObjConn, ObjRS
		Dim GroupCollection, ObjGroup,StrUserName, StrDomName, StrSQL
		Dim GroupsList,WriteFile
		GroupsList = &quot;&quot;
		Set ObjRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
		StrDomName = Trim(ObjRootDSE.Get(&quot;DefaultNamingContext&quot;))
		Set ObjRootDSE = Nothing
		&#039;StrUserName = InputBox(&quot;Enter user login&quot;, &quot;Info needed&quot;, &quot;&quot;)
		StrUserName = &quot;GilmullinRR&quot;
		StrSQL = &quot;Select ADsPath From &#039;LDAP://&quot; &amp; StrDomName &amp; &quot;&#039; Where ObjectCategory = &#039;User&#039; AND SAMAccountName = &#039;&quot; &amp; StrUserName &amp; &quot;&#039;&quot;
		Set ObjConn = CreateObject(&quot;ADODB.Connection&quot;)
		ObjConn.Provider = &quot;ADsDSOObject&quot;:  ObjConn.Open &quot;Active Directory Provider&quot;
		Set ObjRS = CreateObject(&quot;ADODB.Recordset&quot;)
		ObjRS.Open StrSQL, ObjConn
		If Not ObjRS.EOF Then
			ObjRS.MoveLast: ObjRS.MoveFirst
			Set ObjUser = GetObject (Trim(ObjRS.Fields(&quot;ADsPath&quot;).Value))
			Set GroupCollection = ObjUser.Groups
			strHtml = &quot;Looking for groups &quot; &amp; StrUserName &amp; &quot; is member of. This may take some time...&quot;
			For Each ObjGroup In GroupCollection
				GroupsList = GroupsList &amp; VbCrLf &amp; &quot;&lt;br&gt;&quot; &amp; ObjGroup.CN 
				CheckForNestedGroup ObjGroup
			Next
			Set ObjGroup = Nothing: Set GroupCollection = Nothing:  Set ObjUser = Nothing
			strHtml = GroupsList
		Else
			strHtml = &quot;Couldn&#039;t find user &quot; &amp; StrUserName &amp; &quot; in AD.&quot;
		End If
		ObjRS.Close:    Set ObjRS = Nothing
		ObjConn.Close:  Set ObjConn = Nothing
		vuvod.innerHTML = strHtml
	end sub</code></pre></div><p>Оригинал .vbs<br /></p><div class="codebox"><pre><code>&#039; ===============================================================================================================
&#039; Get All Group-Membership of a User
&#039; This Script will list All Groups, Including Nested Groups, Where a specified User-Account is a Member
&#039; ===============================================================================================================

Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppend = 8

Dim ObjUser, ObjRootDSE, ObjConn, ObjRS
Dim GroupCollection, ObjGroup
Dim StrUserName, StrDomName, StrSQL
Dim GroupsList
Dim WriteFile

GroupsList = &quot;&quot;

Set ObjRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
StrDomName = Trim(ObjRootDSE.Get(&quot;DefaultNamingContext&quot;))
Set ObjRootDSE = Nothing

StrUserName = InputBox(&quot;Enter user login&quot;, &quot;Info needed&quot;, &quot;&quot;)
StrSQL = &quot;Select ADsPath From &#039;LDAP://&quot; &amp; StrDomName &amp; &quot;&#039; Where ObjectCategory = &#039;User&#039; AND SAMAccountName = &#039;&quot; &amp; StrUserName &amp; &quot;&#039;&quot;

Set ObjConn = CreateObject(&quot;ADODB.Connection&quot;)
ObjConn.Provider = &quot;ADsDSOObject&quot;:  ObjConn.Open &quot;Active Directory Provider&quot;
Set ObjRS = CreateObject(&quot;ADODB.Recordset&quot;)
ObjRS.Open StrSQL, ObjConn
If Not ObjRS.EOF Then
    ObjRS.MoveLast: ObjRS.MoveFirst
    Set ObjUser = GetObject (Trim(ObjRS.Fields(&quot;ADsPath&quot;).Value))
    Set GroupCollection = ObjUser.Groups
    WScript.Echo &quot;Looking for groups &quot; &amp; StrUserName &amp; &quot; is member of. This may take some time...&quot;
    &#039;Groups with direct membership, and calling recursive function for nested groups
    For Each ObjGroup In GroupCollection
        GroupsList = GroupsList + ObjGroup.CN + VbCrLf
        CheckForNestedGroup ObjGroup
    Next
    Set ObjGroup = Nothing: Set GroupCollection = Nothing:  Set ObjUser = Nothing
    &#039;Writing list in a file named Groups &lt;username&gt;.txt
    Set WriteFile = WScript.CreateObject(&quot;WScript.Shell&quot;)
        &#039;Dim fso, f
       &#039; Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
        &#039;Set f = fso.OpenTextFile(&quot;Groups &quot; &amp; StrUserName &amp; &quot;.txt&quot;, ForWriting,true)
       &#039; f.write(GroupsList)
      &#039;  f.Close
	  msgbox GroupsList
        WScript.Echo &quot;You can find the list in the Groups &quot; &amp;StrUserName &amp; &quot;.txt file that has just been created.&quot;
Else
    WScript.Echo &quot;Couldn&#039;t find user &quot; &amp; StrUserName &amp; &quot; in AD.&quot;
End If
ObjRS.Close:    Set ObjRS = Nothing
ObjConn.Close:  Set ObjConn = Nothing

Private Sub CheckForNestedGroup(ObjThisGroupNestingCheck)
    On Error Resume Next
    Dim AllMembersCollection, StrMember, StrADsPath, ObjThisIsNestedGroup, TabAdd, i 
    AllMembersCollection = ObjThisGroupNestingCheck.GetEx(&quot;MemberOf&quot;)
    For Each StrMember in AllMembersCollection
        If StrMember &lt;&gt; &quot;&quot; Then
            StrADsPath = &quot;LDAP://&quot; &amp; StrMember
            Set ObjThisIsNestedGroup = GetObject(StrADsPath)
            &#039;If InStr(GroupsList, ObjThisIsNestedGroup.CN) = 0 Then (Uncomment this If and indent lines below to remove groups already in the list)
            TabAdd = &quot;&quot;
            For i = 0 to Recurcount
                TabAdd = TabAdd &amp; vbTab
            Next
            GroupsList = GroupsList &amp; TabAdd &amp; &quot; &quot; &amp; ObjThisIsNestedGroup.CN &amp; VbCrLf
            &#039;End If
            &#039;Recursion to include nested groups of nested groups
            Recurcount = Recurcount + 1
            CheckForNestedGroup ObjThisIsNestedGroup
            Recurcount = Recurcount - 1
        End If
    Next
    Set ObjThisIsNestedGroup = Nothing: Set StrMember = Nothing:    Set AllMembersCollection = Nothing
End Sub</code></pre></div>]]></content>
			<author>
				<name><![CDATA[shade45]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33296</uri>
			</author>
			<updated>2015-12-22T11:02:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99851#p99851</id>
		</entry>
</feed>
