您目前已離線,請等候您的網際網路重新連線

如何使用 Visual Basic 指令碼, 請清除 SidHistory

重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。如果您發現錯誤,並想要協助我們進行改善,請填寫本篇文章下方的問卷。

按一下這裡查看此文章的英文版本:295758
本文已封存。本文係以「現狀」提供且不會再更新。
結論
Microsoft Visual Basic Script (VBScript) 本篇文章中所提供會在目錄中尋找的物件由其名稱並嘗試清除 sidHistory 為該物件。 具有選擇性參數為 和 , 以協助在搜尋中。
其他相關資訊
當使用者物件會從一個網域移到另一個, 新安全性識別元 (SID) 必須為使用者帳戶產生並儲存在 屬性。 新的值寫入至屬性之前, 先前的值會複製到的使用者物件, () 另一個屬性。 這個屬性可以儲存多個值。 在每次使用者物件移動到另一個網域, 新 SID 會產生並儲存在 屬性, 另一個值加入 中的舊 SID 的清單。 有時候可能需要以清除 。

下列 VBScript 程式碼將會從命令列引數中指定之目錄物件移除 屬性 (Attribute)。
  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

警告:本文為自動翻譯

內容

文章識別碼:295758 - 最後檢閱時間:12/06/2015 02:01:39 - 修訂: 3.2

Microsoft Windows 2000 Server, Microsoft Active Directory Service Interfaces 2.5

  • kbnosurvey kbarchive kbhowto kb32bitonly kbprb KB295758 KbMtzh kbmt
意見反應