2016-08-03 5 views
0

こんにちは私は、ユーザー名を確認して特定のアクティブな状態にあるかどうかを確認できるスクリプトを作成する方法を理解できたら、ディレクトリグループ。しかし、グループは親ドメインにあるので、Midwest.Contoso.comというドメインと "John Doe"というドメインを持っているので、Contoso.comだけにあるグループtop_level_adminに対してクエリを実行できる必要があります。VBスクリプトがVBScriptを使用して異なるドメインのグループであるかどうかをテストする

私が見つけたすべてのスクリプトは、親ドメイン内のグループを見ることなく、中西部ドメインのクエリのみを実行しているようです。私はVBScript内のADOの機能について何も知りません。誰かが共有できるくらい寛大なスクリプトを持っているので、VBScriptingについてもっと学ぶまで少し時間を節約できますか?

グループの名前とユーザー名を入力してマシンから照会を実行することはできますが、今は3日間これを混乱させてしまいました。私はいくつかの助けを求めるだろうと思った。

ここでは、私が必要としているように親ドメインにアクセスし、フォレスト全体からグループとユーザーに関する情報を収集するため、私の仕事をしているコードを示します。あなたが期待されるグループが表示されない場合は、

Set objNetwork = CreateObject("WScript.Network") 
strDomain = objNetwork.UserDomain 
strUser = objNetwork.UserName 
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser) 

Dim groups 
For Each objGroup In objUser.Groups 
    groups = groups & objGroup.Name & vbCRLF 
Next 

MsgBox groups 

で始まりますが、ADSIエディタまたはLDAPブラウザを使用してそれを見ることを確認できる場所

'Flush out all domain names found in AD and add them to arrDomainNames 

     set objRootDSE = GetObject("LDAP://RootDSE") 

     strBase   = "<LDAP://cn=Partitions," & objRootDSE.Get("ConfigurationNamingContext") & ">;" 

     strFilter  = "(&(objectcategory=crossRef)(systemFlags=3));" 

     strAttrs   = "name,trustParent,nCName,dnsRoot,distinguishedName;" 

     strScope   = "onelevel" 

     set objConn  = CreateObject("ADODB.Connection") 

     objConn.Provider = "ADsDSOObject" 

     objConn.Open "Active Directory Provider" 

     set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope) 

     objRS.MoveFirst 


     set arrDomainNames  = CreateObject("Scripting.Dictionary") 

     set dicDomainHierarchy = CreateObject("Scripting.Dictionary") 

     set dicDomainRoot  = CreateObject("Scripting.Dictionary") 


     while not objRS.EOF 

      dicDomainRoot.Add objRS.Fields("name").Value, objRS.Fields("nCName").Value 

       if objRS.Fields("trustParent").Value <> "" then 

        arrDomainNames.Add objRS.Fields("name").Value, 0 

        set objDomainParent = GetObject("LDAP://" & objRS.Fields("trustParent").Value) 

        dicDomainHierarchy.Add objRS.Fields("name").Value,objDomainParent.Get("name") 

       else 

        arrDomainNames.Add objRS.Fields("name").Value, 1 

       end if 

       objRS.MoveNext 

     wend 


     'Attach to Active Directory 

     Set adoCommand = CreateObject("ADODB.Command") 

     Set adoConnection = CreateObject("ADODB.Connection") 

     adoConnection.Provider = "ADsDSOObject" 

     adoConnection.Open "Active Directory Provider" 

     adoCommand.ActiveConnection = adoConnection 


     for each strDomain in arrDomainNames 

      strBase = "<LDAP://" & strDomain & ">" 

      strFilter = "(&(objectCategory=group)(objectClass=group))" 

      strAttributes = "name,cn,member" 

      strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" 

      adoCommand.CommandText = strQuery 

      adoCommand.Properties("Page Size") = 100 

      adoCommand.Properties("Timeout") = 30 

      adoCommand.Properties("Cache Results") = False 

      adoCommand.Properties("Sort On") = "cn" 

      Set adoRecordset = adoCommand.Execute 

      inNumGroups = 0 

      Wscript.Echo ("Pre-Processing " & strFilter & " Data...") 

      '===Write information to Export File=== 

      While Not adoRecordset.EOF 

       'working code 

       arrMember = adoRecordset.Fields("member") 

       if IsArray(arrmember) then 

        For each strMember in arrMember 

         'workingcode 

         msgbox adoRecordset.Fields("cn") & vbCRLF & strMember 

        Next 

       else 

        msgbox adoRecordset.Fields("cn") & vbCRLF & "This group has no members" 

       end if 

       adoRecordset.MoveNext 

      wend 

     Next 
+0

私たちあなたのコードに深いダイビングをする前に - あなたはLDAP経由でADにアクセスしたいので、 - あなたが必要なユーザーおよびLDAPブラウザhttp://www.ldapadministrator.com(またはお好みのツールを使用して、彼のグループを見ることができることを確認してください)。あなたが探しているものとあなたのADがどのようにセットアップされているかを理解するのに役立ちます。 – Alex

答えて

0

私は結局答えがありましたが、助けてくれてありがとう!

strGroupDN = "CN=UserGroup,OU=MainOU,OU=SecondaryGroup,OU=MainGroups,DC=Primary,DC=FQDN,DC=com" 
Set objGroup = GetObject("LDAP://" & strGroupDN) 

‘wscript.echo strGroupDN 

‘Uncomment the following three lines to have the system check the current users directory information rather than specifically specifying the user like it currently is below. 
'Set objADSysInfo = CreateObject("ADSystemInfo") 
' strUserDN will look like CN=TestUser1,OU=End Users,CN=UserGroup,OU=MainOU,OU=SecondaryGroup,OU=MainGroups,DC=Primary,DC=FQDN,DC=com 
'strUserDN = objADSysInfo.UserName 


strUserDn = "CN=TestUser1,OU=End Users,CN=UserGroup,OU=MainOU,OU=SecondaryGroup,OU=MainGroups,DC=Primary,DC=FQDN,DC=com" 
‘wscript.echo strUserDN 
If objGroup.IsMember("LDAP://" & strUserDN) Then 
    wscript.echo "The User is in the group" 
    ' The user is in the group so run the following actions 

    else 

    wscript.echo "The user is not in the group" 
End If 
0

です。

+0

私はそのスクリプトのシンプルさが好きですが、私がログインしている現在のドメインにしかアクセスしません。既定では、自分のドメインとしてmidwest.contoso.comにログインしていますが、contoso.comの親ドメイン内に特別なグループのグループがあります。これは、midwest.contoso.com内のメンバーであるグループのみを出力します。 –

+0

私は先に進んで、私が取り組んでいるコードのいくつかを添付して試してみましょう。しかし、私は、私が必要と信じているように、ADBオブジェクトで動作するようにVB Scriptingについて十分に知りませんでした。私は完全に間違っていて、私が必要とするものを得るために非常に長い道を行くことができます。もしあなたがそれを働かせる方法や、アクティブなディレクトリの親ディレクトリから情報を得るより簡単な方法を知っていれば、 –

+0

私が添付したコードでは、現在のところ、フォレスト全体のすべてのユーザーに対してすべてのグループが取得されていますが、特に確認したいグループ名とユーザーに対して何らかのチェックを行うために結果をフィルタリングする方法が必要です。その後、ユーザーがメンバーであるかどうかを確認した後、その結果に基づいてメッセージボックスを表示します。 –

関連する問題