I have this somewhere, just to get it right, you want to connect in AD using LDAP, but while the workstation or the logged on user is not part of the domain. ??
Ok here we go this should do, just modify the code to delete computer account rather then add it.
Would do it, but my hard drive of 2000 server has gone wrong, sorry
code:
; Set the login credential
$sUser = "Administrator"
$sPassword = "password"
; Set the domain controler and the proper context
$sDomain = "domaincontroller"
$sContainer = "OU=Clients"
; Connect to ADS with the provided login credential
$oProvider = GetObject("LDAP:")
$rootDSE = $oProvider.OpenDSObject("LDAP://" + $sDomain + "/RootDSE", $sUser, $sPassword, 1)
; Collect the proper path, and get the OU where the machine should be created
$sPath = "LDAP://" + $sDomain + "/" + $sContainer + ","
$sPath = $sPath + $rootDSE.Get("defaultNamingContext")
$MyOU = $oProvider.OpenDSObject($sPath, $sUser, $sPassword, 1)
IF NOT $MyOU = 0
$MachineObj = $MyOU.Create("computer", "CN=NewPC")
IF NOT $MachineObj = 0
; Set mandatory properties and save object
$MachineObj.samAccountName = "NewPC"
$MachineObj.SetInfo
; Activate the computer account
$MachineObj.AccountDisabled = False
$MachineObj.SetInfo
? @ERROR
?
? @SERROR
ELSE
? @ERROR
?
? @SERROR
ENDIF
ELSE
? @ERROR
?
? @SERROR
ENDIF
[ 26. June 2003, 22:46: Message edited by: Richard Farthing ]