_ADDeleteObject Wie User OU herausfinden

  • Hallo zusammen,

    stehe gerade vor einen kleinen Problem,

    wie finde ich bei _ADDeleteObject die UserOU herraus?

    Wenn ich im Script schreibe: _ADDeleteObject("OU=CO-CP,OU=CO,OU=Accounts,DC=XXXXX,DC=XXXX",$user, "user") funktioniert es. Ich möchte aber das er automatisch die OU findet


    weiteres siehe ADfuntions.au3

    Func _ADDeleteObject($ou, $object, $type)
    If StringLeft($object, 3) <> "CN=" Then
    $object = "CN=" & StringReplace($object, ",", "\,")
    EndIf
    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $ou)
    $objOU.Delete ($type, $object)
    $ObjOU = 0
    Return 1
    EndFunc ;==>_ADDeleteObject


    Hoffe ihr könnt mir helfen...

    Einmal editiert, zuletzt von Flitzer (3. April 2008 um 18:14)

    • Offizieller Beitrag

    Ich hab im Web ein Skript gefunden, dass ich mal AutoIt-fähig gemacht habe.
    Ziel des Skripts ist eine automatische Anmeldung und dafür die notwendigen Daten (u.a. die OU des Users) zu ermitteln.
    Kann es selbst nicht testen, weiß also nicht ob es wirklich funktioniert.
    Vielleicht bringt es dich weiter.

    Spoiler anzeigen
    [autoit]

    ; Create all necessary COM objects.
    ;--------------------------------------------------------------------------
    $WSHShell = ObjCreate("WScript.Shell")
    $AppShell = ObjCreate("Shell.Application")
    $WSHNetwork = ObjCreate("WScript.Network")
    $WSHfso = ObjCreate("Scripting.FileSystemObject")
    $objADSysInfo = ObjCreate("ADSystemInfo")
    $objFavoritesFolderRef = $AppShell.Namespace('FAVORITES')
    $objFavoritesFolder = $objFavoritesFolderRef.Self
    $objNetHoodFolderRef = $AppShell.Namespace('NETHOOD')
    $objNetHoodFolder = $objNetHoodFolderRef.Self
    $FavoritesDir = $objFavoritesFolder.Path
    $NetHoodDir = $objNetHoodFolder.Path

    [/autoit] [autoit][/autoit] [autoit]

    ; find the domain name and login-parameters
    ;--------------------------------------------------------------------------
    $strComputer = $WSHNetwork.ComputerName
    $objDomain = ObjGet("LDAP://rootDse")
    $strConfigNC = $objDomain.Get("configurationNamingContext")
    $SiteName = $objADSysInfo.SiteName
    $objSite = ObjGet("LDAP://CN=" & $SiteName & ",CN=Sites," & $strConfigNC)
    $SiteDesc = $objSite.Get("description")
    $DomainString = $objDomain.Get("dnsHostName")
    $WinDir = $WshShell.ExpandEnvironmentStrings("%WinDir%")
    $clientname = $WshShell.ExpandEnvironmentStrings("%clientname%")
    $UserString = $WSHNetwork.UserName
    $AdsPath = $objDomain.ADsPath($UserString)
    $adsUser = ObjGet($AdsPath)
    $adsParent = ObjGet($adsUser.Parent)
    $UserOU = $adsParent.Get("ou")
    $UserObj = ObjGet("WinNT://" & $DomainString & "/" & $UserString)
    $ADSCompPath = $objDomain.ADsPath($strComputer)
    $CompObj = ObjGet($ADSCompPath)

    [/autoit]
  • es geht... juhu

    Für alle die das gleiche Problem haben hier der Quelltext (hoffe das ist überhaupt richtig

    Spoiler anzeigen
    [autoit]


    Func _deladuser($object, $type)
    If _ADObjectExists($delusername) = 1 Then
    $ADS_SCOPE_SUBTREE = 2
    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties("Page Size") = 1000
    $objCommand.Properties ("Searchscope") = $ADS_SCOPE_SUBTREE
    $objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://dc=DOMÄNE,dc=com' WHERE objectCategory='user' AND name='" & $object & "'"
    $objRecordSet = $objCommand.Execute
    $objRecordSet.MoveFirst
    Do
    $AD_OU_INFO = $objRecordSet.Fields("ADsPath" ).Value
    $objRecordSet.MoveNext
    Until $objRecordSet.EOF
    $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD
    $objConnection.ConnectionString = "Provider=ADsDSOObject"
    $objConnection.Open ("Active Directory Provider") ; Open connection to AD
    $AD_OU_INFO = StringTrimLeft($AD_OU_INFO, 7)
    $arrayou = StringSplit($AD_OU_INFO,",")
    $oupath = $arrayou[2]
    For $i = 3 to $arrayou[0]
    $oupath = $oupath & "," & $arrayou[$i]
    Next
    If StringLeft($object, 3) <> "CN=" Then
    $object = "CN=" & StringReplace($object, ",", "\,")
    EndIf
    $ObjOU = ObjGet("LDAP://" & $strHostServer & "/" & $oupath)
    $objOU.Delete ($type, $object)
    $ObjOU = 0
    Return 1
    Else
    Return 2
    EndIf
    EndFunc

    [/autoit]