<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBS: вывод в csv информации о группах, в которых пользователи из OU]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=6111</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6111&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBS: вывод в csv информации о группах, в которых пользователи из OU».]]></description>
		<lastBuildDate>Sat, 13 Aug 2011 06:04:06 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBS: вывод в csv информации о группах, в которых пользователи из OU]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=50590#p50590</link>
			<description><![CDATA[<p>Язык программирования укажите в названии темы.</p>]]></description>
			<author><![CDATA[null@example.com (JSmаn)]]></author>
			<pubDate>Sat, 13 Aug 2011 06:04:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=50590#p50590</guid>
		</item>
		<item>
			<title><![CDATA[VBS: вывод в csv информации о группах, в которых пользователи из OU]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=50574#p50574</link>
			<description><![CDATA[<p>Добрый день!</p><p>Можно ли переделать этот скрипт на vbs с wisesoft, чтоб скрипт возвращал атрибут memberOf в виде display name групп, а не их DN? Он выдает группы в виде:<br /></p><div class="codebox"><pre><code>CN=Guest,CN=Users,DC=MyDomain,DC=local
CN=Guests,CN=Builtin,DC=MyDomain,DC=local
CN=SUPPORT_388945a0,CN=Users,DC=MyDomain,DC=local
CN=HelpServicesGroup,CN=Users,DC=MyDomain,DC=local</code></pre></div><p>Вот сам скрипт:<br /></p><div class="codebox"><pre><code>Option Explicit

dim FileName, multivaluedsep,strAttributes
dim strFilter, strRoot, strScope
dim cmd, rs,cn
Dim objRoot, objFSO,objCSV
Dim comma, q, i, mvsep, strAttribute, strValue,strSearchAttributes
dim objUser

&#039; ********************* Setup *********************

&#039; The filename of the csv file produced by this script
FileName =&quot;GetGroupList.csv&quot;
&#039; Seperator used for multi-valued attributes
multivaluedsep = &quot;;&quot;
&#039; comma seperated list of attributes to export
strAttributes = &quot;sAMAccountName,givenName,initials,sn,displayName,memberOf,description,physicalDeliveryOfficeName,memberOf,&quot; &amp; _
        &quot;telephoneNumber,mail,wWWHomePage,cn,terminalservicesprofilepath,terminalserviceshomedrive,terminalserviceshomedirectory,allowlogon&quot;

&#039; Default filter for all user accounts (ammend if required)
strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;
&#039; scope of search (default is subtree - search all child OUs)
strScope = &quot;subtree&quot;
&#039; search root. e.g. ou=MyUsers,dc=wisesoft,dc=co,dc=uk
&#039; leave blank to search from domain root
strRoot = &quot;OU=vip,OU=users,DC=firma,DC=ru&quot;

&#039; *************************************************

q = &quot;&quot;&quot;&quot;
comma = &quot;&quot; &#039; first column does not require a preceding comma
i = 0 
Set objFSO = createobject(&quot;Scripting.FileSystemObject&quot;)
Set objCSV = objFSO.createtextfile(FileName)

&#039; Create CSV header row and get attributes to use in search
For Each strAttribute In SPLIT(strAttributes,&quot;,&quot;)
    Select Case LCASE(strAttribute)
        Case &quot;terminalservicesprofilepath&quot;,&quot;terminalserviceshomedrive&quot;,&quot;terminalserviceshomedirectory&quot;,&quot;allowlogon&quot;
            &#039; Terminal services attributes are stored in the userparameters attribute and can be read individually
            &#039; via the IADsTSUserEx interface. This requires us to bind to each user account returned by the search (slow)
            &#039; Add the &quot;adspath&quot; attribute to allow us to bind to the user account where terminal services attributes are 
            &#039; specified
            If INSTR(1,strSearchAttributes,&quot;adspath&quot;,1) = 0 Then &#039; Check if we don&#039;t already have adspath attribute
                IF strSearchAttributes &lt;&gt; &quot;&quot; Then
                    strSearchAttributes = strSearchAttributes &amp; &quot;,&quot;
                End If
                strSearchAttributes = strSearchAttributes &amp; &quot;adspath&quot;
            End If
        Case Else
            &#039; Append attribute to the search attributes
            If strSearchAttributes &lt;&gt; &quot;&quot; Then
                strSearchAttributes = strSearchAttributes &amp; &quot;,&quot;
            End If
            strSearchAttributes = strSearchAttributes &amp; strAttribute
    END Select
    &#039; Write CSV File Header
    objcsv.write(comma &amp; q &amp; strAttribute &amp; q)
    comma = &quot;,&quot; &#039; all columns apart from the first column require a preceding comma
    i = i + 1
Next

set cmd = createobject(&quot;ADODB.Command&quot;)
set cn = createobject(&quot;ADODB.Connection&quot;)
set rs = createobject(&quot;ADODB.Recordset&quot;)

cn.open &quot;Provider=ADsDSOObject;&quot;
cmd.activeconnection = cn

&#039; If root = &quot;&quot;, use the default naming context (current domain)
if strRoot = &quot;&quot; then
    set objRoot = getobject(&quot;LDAP://RootDSE&quot;)
    strRoot = objRoot.get(&quot;defaultNamingContext&quot;) 
end if

cmd.commandtext = &quot;&lt;LDAP://&quot; &amp; strRoot &amp; &quot;&gt;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; _
          strSearchAttributes &amp; &quot;;&quot; &amp; strScope

&#039;**** Bypass 1000 record limitation ****
cmd.properties(&quot;page size&quot;)=1000

set rs = cmd.execute

&#039; for each item returned by the Active Directory query
while rs.eof &lt;&gt; true and rs.bof &lt;&gt; True
    Set objUser = Nothing &#039; Used only for terminal services attributes
    comma=&quot;&quot; &#039; first column does not require a preceding comma
    objcsv.writeline &#039; Start a new line
    &#039; For each column in the result set
    for each strAttribute in SPLIT(strAttributes,&quot;,&quot;)
        select case strAttribute
            case &quot;terminalservicesprofilepath&quot;
                &#039; Bind to user account if required (only bind once per user if more than 1 
                &#039; terminal services attribute is specified)
                If objUser Is Nothing Then
                    Set objUser = GETOBJECT(rs(&quot;adspath&quot;))
                End If
                objCSV.Write(comma &amp; q &amp; replace(objUser.TerminalServicesProfilePath,q,q &amp; q) &amp; q)
            case &quot;terminalserviceshomedrive&quot;
                &#039; Bind to user account if required (only bind once per user if more than 1 
                &#039; terminal services attribute is specified)
                IF objUSer IS NOTHING Then
                    SET objUser = GETOBJECT(rs(&quot;adspath&quot;))
                End If
                objCSV.Write(comma &amp; q &amp; objUser.TerminalServicesHomeDrive &amp; q)
            case &quot;terminalserviceshomedirectory&quot;
                &#039; Bind to user account if required (only bind once per user if more than 1 
                &#039; terminal services attribute is specified)
                IF objUSer IS NOTHING Then
                    SET objUser = GETOBJECT(rs(&quot;adspath&quot;))
                End If
                objCSV.Write(comma &amp; q &amp; replace(objUser.TerminalServicesHomeDirectory,q,q &amp; q) &amp; q)
            case &quot;allowlogon&quot;
                &#039; Bind to user account if required (only bind once per user if more than 1 
                &#039; terminal services attribute is specified)
                IF objUSer IS NOTHING Then
                    SET objUser = GETOBJECT(rs(&quot;adspath&quot;))
                End If
                objCSV.Write(comma &amp; q &amp; objUser.AllowLogon &amp; q)
            case else
                select case typename(rs(strAttribute).value)
                    case &quot;Null&quot; &#039; handle null value
                        objcsv.write(comma &amp; q &amp; q)
                    case &quot;Variant()&quot; &#039; multi-valued attribute
                        &#039; Multi-valued attributes will be seperated by value specified in
                        &#039; &quot;multivaluedsep&quot; variable
                        mvsep = &quot;&quot; &#039;No seperator required for first value
                        objcsv.write(comma &amp; q)
                        for each strValue in rs(strAttribute).Value
                            &#039; Write value
                            &#039; single double quotes &quot; are replaced by double double quotes &quot;&quot;
                            objcsv.write(mvsep &amp; replace(strValue,q,q &amp; q))
                            mvsep = multivaluedsep &#039; seperator used when more than one value returned
                        next
                        objcsv.write(q)
                    case else
                        &#039; Write value
                        &#039; single double quotes &quot; are replaced by double double quotes &quot;&quot;
                        objcsv.write(comma &amp; q &amp; replace(rs(strAttribute).value,q,q &amp; q) &amp; q)
                end select
        end select
        
        comma = &quot;,&quot; &#039; all columns apart from the first column require a preceding comma
    next
    rs.movenext
wend

&#039; Close csv file and ADO connection
cn.close
objCSV.Close

wscript.echo &quot;Finished&quot;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (dost)]]></author>
			<pubDate>Fri, 12 Aug 2011 14:02:16 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=50574#p50574</guid>
		</item>
	</channel>
</rss>
