Lm th? no ? s? d?ng Visual Basic Script ? xa SidHistory

D?ch tiu ? D?ch tiu ?
ID c?a bi: 295758 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?


Microsoft Visual Basic Script (VBScript) ?c cung c?p trong bi vi?t ny s? t?m th?y m?t ?i t?ng theo tn trong th m?c v c? g?ng ? xa sidHistory cho ?i t?ng . th? ny c cc tham s? ty ch?n cho objectClass v objectCategory ? gip ? trong vi?c t?m ki?m.


Khi m?t ?i t?ng ng?i dng di chuy?n t? m?t tn mi?n khc, m?t ?nh danh b?o m?t m?i (SID) ph?i ?c t?o ra cho cc ti kho?n ng?i s? d?ng v lu tr? trong cc ?i t?ng-SID b?t ?ng s?n. Tr?c khi cc gi tr? m?i ?c vi?t cho ti s?n, gi tr? tr?c sao chp vo b?t ?ng s?n khc c?a m?t ?i t?ng ng?i s? d?ng, SID-l?ch s? (sidHistory). ?c tnh ny c th? ch?a nhi?u gi tr?. M?i khi m?t ?i t?ng ng?i dng di chuy?n vng khc, m?t SID m?i ?c t?o ra v lu tr? trong cc ?i t?ng-SID b?t ?ng s?n v gi tr? khc ?c thm vo danh sch c? SIDs trong SID-l?ch s?. i khi n c th? l c?n thi?t ? xa cc sidHistory.

VBScript m? sau s? lo?i b? cc sidHistory thu?c tnh t? ?i t?ng th m?c ? ch? ?nh trong cc ?i s? d?ng l?nh.
  1. M? Microsoft Notepad.
  2. Copy o?n m? sau y v dn n vo ti li?u Notepad c?a b?n.
    Dim strFilter 'As String
    Dim oConnection 'As ADODB.Connection
    Dim oRecordSet 'As ADODB.RecordSet
    Dim strQuery 'As String
    Dim strDomainNC 'As String
    Dim oRootDSE 'As IADs
    Dim vArray 'As Variant()
    Dim vSid 'As Variant
    Dim oDirObject 'As Variant
    ' Parse the command line and set the query filter
    ' Find the domain naming context
    set oRootDSE = GetObject("LDAP://RootDSE")
    strDomainNC = oRootDSE.Get("defaultNamingContext")
    set oRootDSE = Nothing
    ' Setup the ADO connection
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Provider = "ADsDSOObject"
    oConnection.Open "ADs Provider"
    strQuery = "<LDAP://" & strDomainNC & ">;" & strFilter & ";distinguishedName,objectClass,name,sidHistory;subtree"
    'Execute the query
    set oRecordSet = oConnection.Execute(strQuery)
    if oRecordSet.Eof then
      WScript.Echo "No objects were found"
      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"
    	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) 
            WScript.Echo "The sidHistory has been cleared for this object!"
         End if
    End if
    'Clean up
    Set oRecordset = Nothing
    Set 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
       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)
            end if
         End if
    'Should be okay to build filter  
    If strName = "" Then
      WScript.Echo "A name parameter must be given"
      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 filter
    End if
    End 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"
    End Sub
  3. Lu ti li?u nh C:\ClearSidHistory.vbs
  4. Ch?y m?. Vi?c s? d?ng cho ClearSidHistory.vbs l nh sau:
    cscript.exe ClearSidHistory.vbs - n =<name></name> [-o =<objectcategory></objectcategory>] [-c=<objectclass></objectclass>]

    -n =<name of="" the="" object="" you="" are="" looking="" for=""></name>
    -o =<objectcategory of="" the="" object="" you="" are="" looking="" for=""></objectcategory>
    -c =<objectclass of="" the="" object="" you="" are="" looking="" for=""></objectclass>

    V d?:

    cscript.exe ClearSidHistory.vbs - n = lin h? c?a ti
    cscript.exe ClearSidHistory.vbs - n = Computer1 -o = my tnh
    cscript.exe ClearSidHistory.vbs - n = James Smith -o = ng?i - c = ng?i dng

Thu?c tnh

ID c?a bi: 295758 - L?n xem xt sau cng: 25 Thang Tam 2011 - Xem xt l?i: 3.0
p d?ng
  • Microsoft Windows 2000 Server
T? kha:
kb32bitonly kbhowto kbprb kbmt KB295758 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:295758

Cung cp Phan hi


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com