반응형
이렇게 하면 dclist 얻을 수 있다....
Set objRootDSE = GetObject("LDAP://RootDSE")
strCNC = objRootDSE.Get("configurationNamingContext")
Set objEnumConnection = CreateObject("ADODB.Connection")
Set objEnumCommand = CreateObject("ADODB.Command")
objEnumConnection.Provider = "ADsDSOObject"
objEnumConnection.Open "Active Directory Provider"
Set objEnumCommand.ActiveConnection = objEnumConnection
objEnumCommand.CommandText = "<LDAP://" & strCNC & ">;(objectCategory=nTDSDSA);name,distinguishedName;subtree"
Set objEnumRecordSet = objEnumCommand.Execute
objEnumRecordSet.MoveFirst
Do Until objEnumRecordSet.EOF
dcArray = Split(objEnumRecordSet.Fields("distinguishedName").Value, ",", -1, 1)
nameArray = Split(dcArray(1), "=", -1, 1)
WScript.Echo nameArray(1)
objEnumRecordSet.MoveNext
Loop
아래는 c# 에서 dclist 얻어서 특정 컴퓨터 조회해서 삭제하는거.......
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
string configurationNamingContext =
(string)rootDSE.Properties["configurationNamingContext"].Value;
string defaultNamingContext =
(string)rootDSE.Properties["defaultNamingContext"].Value;
DirectoryEntry deConfig = new DirectoryEntry("LDAP://" + configurationNamingContext);
DirectorySearcher dsConfig = new DirectorySearcher(deConfig);
dsConfig.Filter = "(objectClass=nTDSDSA)";
foreach (SearchResult srDomains in dsConfig.FindAll())
{
DirectoryEntry deDomain = srDomains.GetDirectoryEntry();
if (deDomain != null)
{
string dnsHostName =
deDomain.Parent.Properties["DNSHostName"].Value.ToString();
DirectoryEntry deComputers = new DirectoryEntry("LDAP://" + dnsHostName + "/" + defaultNamingContext);
DirectorySearcher dsComputers = new DirectorySearcher(deComputers);
dsComputers.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn="+computerName+"))";
foreach (SearchResult srComputers in dsComputers.FindAll())
{
DirectoryEntry deComputer = srComputers.GetDirectoryEntry();
if (deComputer != null)
{
deComputer.DeleteTree();
}
}
}
}
Set objRootDSE = GetObject("LDAP://RootDSE")
strCNC = objRootDSE.Get("configurationNamingContext")
Set objEnumConnection = CreateObject("ADODB.Connection")
Set objEnumCommand = CreateObject("ADODB.Command")
objEnumConnection.Provider = "ADsDSOObject"
objEnumConnection.Open "Active Directory Provider"
Set objEnumCommand.ActiveConnection = objEnumConnection
objEnumCommand.CommandText = "<LDAP://" & strCNC & ">;(objectCategory=nTDSDSA);name,distinguishedName;subtree"
Set objEnumRecordSet = objEnumCommand.Execute
objEnumRecordSet.MoveFirst
Do Until objEnumRecordSet.EOF
dcArray = Split(objEnumRecordSet.Fields("distinguishedName").Value, ",", -1, 1)
nameArray = Split(dcArray(1), "=", -1, 1)
WScript.Echo nameArray(1)
objEnumRecordSet.MoveNext
Loop
아래는 c# 에서 dclist 얻어서 특정 컴퓨터 조회해서 삭제하는거.......
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
string configurationNamingContext =
(string)rootDSE.Properties["configurationNamingContext"].Value;
string defaultNamingContext =
(string)rootDSE.Properties["defaultNamingContext"].Value;
DirectoryEntry deConfig = new DirectoryEntry("LDAP://" + configurationNamingContext);
DirectorySearcher dsConfig = new DirectorySearcher(deConfig);
dsConfig.Filter = "(objectClass=nTDSDSA)";
foreach (SearchResult srDomains in dsConfig.FindAll())
{
DirectoryEntry deDomain = srDomains.GetDirectoryEntry();
if (deDomain != null)
{
string dnsHostName =
deDomain.Parent.Properties["DNSHostName"].Value.ToString();
DirectoryEntry deComputers = new DirectoryEntry("LDAP://" + dnsHostName + "/" + defaultNamingContext);
DirectorySearcher dsComputers = new DirectorySearcher(deComputers);
dsComputers.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn="+computerName+"))";
foreach (SearchResult srComputers in dsComputers.FindAll())
{
DirectoryEntry deComputer = srComputers.GetDirectoryEntry();
if (deComputer != null)
{
deComputer.DeleteTree();
}
}
}
}
댓글