VBScript - 更改组类型

时间:2014-07-25 14:00:38

标签: vbscript scripting active-directory

我使用下面的VBscript将几个组的组类型更改为Security。我收到错误"服务器不愿意处理请求"执行objGroup.setinfo时。

感谢有人可以帮忙解决此问题。

Dim strOU, strGroup, objOU, objGroup
Dim strFile, objFile, objFSO
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000
Const ForReading = 1
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_GROUP_TYPE_UNIVERSAL = &H8


strFile = "c:\Temp\GroupNames.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
strNetBIOSDomain = Left(strNetBIOSDomain, _
Len(strNetBIOSDomain) - 1)

Do Until objFile.AtEndOfStream
strNTName = Trim(objFile.ReadLine)
If (strNTName <> "") Then
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName

End If

' Use Get method to retrieve Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
wscript.echo strUSerDN
' Bind to user object in AD.
Set objGroup = GetObject("LDAP://servername

&#34; &安培; strUserDN)

objGroup.Put "groupType", ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

Loop
objFile.Close

1 个答案:

答案 0 :(得分:1)

您还需要指定组范围。您需要“ADS_GROUP_TYPE_ [type] _GROUP或ADS_GROUP_TYPE_SECURITY_ENABLED”,而不仅仅是“ADS_GROUP_TYPE_SECURITY_ENABLED”,其中[type]是GLOBAL,LOCAL或UNIVERSAL。