こんにちは私は、ユーザー名を確認して特定のアクティブな状態にあるかどうかを確認できるスクリプトを作成する方法を理解できたら、ディレクトリグループ。しかし、グループは親ドメインにあるので、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
私たちあなたのコードに深いダイビングをする前に - あなたはLDAP経由でADにアクセスしたいので、 - あなたが必要なユーザーおよびLDAPブラウザhttp://www.ldapadministrator.com(またはお好みのツールを使用して、彼のグループを見ることができることを確認してください)。あなたが探しているものとあなたのADがどのようにセットアップされているかを理解するのに役立ちます。 – Alex