如何使用 VisualBasic 脚本来清除 SidHistory

注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。如果您发现了错误并希望帮助我们提高机器翻译技术,请完成文章末尾的在线调查。

点击这里察看该文章的英文版: 295758
本文已归档。它按“原样”提供,并且不再更新。
概要
Microsoft VisualBasic 脚本 (VBScript) 本文中提供将按名称查找对象目录中并尝试清除该对象 sidHistory。 它具有用于 和 以帮助搜索中可选参数。
更多信息
当用户对象将从一个域移动到另一个, 新安全标识符 (SID) 必须是生成用户帐户和存储在 属性。 在新值写入属性, 以前值复制到用户对象, () 的其他属性。 该属性可容纳多个值。 每次用户对象移动到其他域, 新 SID 是生成并存储在 属性和其他值是添加到 中旧 SID 的列表。 有时可能需要清除 。

以下 VBScript 代码将从命令行参数中指定目录对象删除 属性。
  1. 打开 Microsoft 记事本。
  2. 将以下代码复制并粘贴到记事本文档。
    Const ADS_PROPERTY_DELETE = 4Dim strFilter 'As StringDim oConnection 'As ADODB.ConnectionDim oRecordSet 'As ADODB.RecordSetDim strQuery 'As StringDim strDomainNC 'As StringDim oRootDSE 'As IADsDim vArray 'As Variant()Dim vSid 'As VariantDim oDirObject 'As Variant' Parse the command line and set the query filterParseCommandLine()' Find the domain naming contextset oRootDSE = GetObject("LDAP://RootDSE")strDomainNC = oRootDSE.Get("defaultNamingContext")set oRootDSE = Nothing' Setup the ADO connectionSet oConnection = CreateObject("ADODB.Connection")oConnection.Provider = "ADsDSOObject"oConnection.Open "ADs Provider"strQuery = "<LDAP://" & strDomainNC & ">;" & strFilter & ";distinguishedName,objectClass,name,sidHistory;subtree"'Execute the queryset oRecordSet = oConnection.Execute(strQuery)if oRecordSet.Eof then  WScript.Echo "No objects were found"  WScript.Quit(0)Else  Dim vClasses 'As Variant  Dim strClass 'As String  WScript.Echo "The following objects were found:"  'On Error Resume Next  ' Iterate through the objects that match the filter  While Not oRecordset.Eof     vClasses = oRecordset.Fields("objectClass").Value     strClass = vClasses(UBound(vClasses))     WScript.Echo "Name: " & oRecordset.Fields("name").Value & "   Class: " & strClass & "  DN: " & oRecordset.Fields("distinguishedName").Value     If IsNull(oRecordSet.Fields("sIDHistory").Value ) Then        WScript.Echo "This object does not have a sidHistory"     Else	set oDirObject = GetObject("LDAP://" & oRecordset.Fields("distinguishedName").Value)         vArray = oDirObject.GetEx("sIDHistory")        For Each vSid in vArray         oDirObject.PutEx ADS_PROPERTY_DELETE, "sIDHistory", array(vSid)          oDirObject.SetInfo         Next        WScript.Echo "The sidHistory has been cleared for this object!"     End if          oRecordset.MoveNext  WendEnd if'Clean upSet oRecordset = NothingSet oConnection = Nothing'=========================================================================================================================' The ParseCommandLine subroutine will build the query filter base on the arguments passed to the script.  The bNameFlag' is used so that the name given can have spaces in it.'=========================================================================================================================Sub ParseCommandLine()   Dim vArgs, Value, Equals, I   Dim bNameFlag 'As Boolean   Dim strName 'As String   Dim strObjectCategory 'As String   Dim strObjectClass 'As String   Set vArgs = WScript.Arguments   if VArgs.Count < 1 Then      DisplayUsage()   End if  bNameFlag = False  For I = 0 to vArgs.Count - 1      If Left( vArgs(I) , 1 ) = "/" Or Left( vArgs(I) , 1 ) = "-" Then         Value = ""         Equals = InStr( vArgs(I) , "=" )         If Equals = 0 Then Equals = InStr( vArgs(I) , ":" )         If Equals > 0 Then Value = Mid( vArgs(I) , Equals + 1 )         Select Case LCase( Mid( vArgs(I) , 2 , 1) )   		Case "n" strName = Value			 bNameFlag = True  'This will allow us to catch spaces   		Case "o" strObjectCategory = Value			 bNameFlag = False                Case "c" strObjectClass = Value			 bNameFlag = False		Case Else DisplayUsage         End Select        	     Else 'no dash or slash;  Check if we are giving a name        if bNameFlag Then           strName = strName & " " & vArgs(I)        else           DisplayUsage        end if     End if   Next'Should be okay to build filter  If strName = "" Then  WScript.Echo "A name parameter must be given"  WScript.Quit(1)Else  strFilter = "(&(name=" & strName & ")"  If Len(strObjectCategory) > 0 Then     strFilter = strFilter & "(objectCategory=" & strObjectCategory & ")"  End if  If Len(strObjectClass) > 0 Then     strFilter = strFilter & "(objectClass=" & strObjectClass & ")"  End if  strFilter = strFilter & ")" 'Close filterEnd ifEnd Sub'=========================================================================================================================' The DisplayUsage subroutine will display how to use this script, the objectCategory and objectClass arguments are optional.'=========================================================================================================================Sub DisplayUsage() WScript.Echo "Usage csript.exe " & WScript.ScriptName & vbLF & _      "-n=<name of the object you are looking for>" & vbLF & _     "[-o=<objectCategory of the object you are looking for>]" & vbLF & _     "[-c=<objectClass of the object you are looking for>]"  & vbLF & vbLF & _ 	 "Examples : " & vbLF & _	 WScript.ScriptName & " -n=My Contact" & vbLF & _	 WScript.ScriptName & " -n=Computer1 -o=computer" & vbLF & _ 	 WScript.ScriptName & " -n=James Smith -o=Person -c=user" WScript.Quit(0)End Sub    					
  3. 将文档保存为 C:\ClearSidHistory.vbs
  4. 运行代码。 对于 ClearSidHistory.vbs 用法如下所示:
    cscript.exe ClearSidHistory.vbs -n=<name> [-o=<objectCategory>] [-c=<objectClass>]

    - n =
    - o =
    - c =

    示例:

    cscript.exe ClearSidHistory.vbs -n=My Contact
    cscript.exe ClearSidHistory.vbs -n=Computer1 -o=computer
    cscript.exe ClearSidHistory.vbs -n=James Smith -o=Person -c=user

属性

文章 ID:295758 - 上次审阅时间:12/06/2015 02:01:38 - 修订版本: 3.2

Microsoft Windows 2000 Server, Microsoft Active Directory Service Interfaces 2.5

  • kbnosurvey kbarchive kbhowto kb32bitonly kbprb KB295758 KbMtzh kbmt
反馈