{"id":299,"date":"2014-09-23T15:17:52","date_gmt":"2014-09-23T19:17:52","guid":{"rendered":"http:\/\/adsecurity.org\/?p=299"},"modified":"2014-12-31T21:24:02","modified_gmt":"2015-01-01T02:24:02","slug":"powershell-code-active-directory-domain-controller-discovery","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=299","title":{"rendered":"PowerShell Code: Active Directory Domain Controller Discovery"},"content":{"rendered":"<p>There are several different ways to find AD Domain Controllers (DCs).<\/p>\n<p>Here are a few:<\/p>\n<p><span style=\"text-decoration: underline;\">AD PowerShell Module: Discover the closest Domain Controller running the AD web services (support PowerShell AD cmdlets):<\/span><\/p>\n<p><em>import-module activedirectory<\/em><br \/>\n<em>Get-ADDomainController -discover -forcediscover -nextclosestsite -service ADWS<\/em><\/p>\n<ul>\n<li>discover &#8211; find a DC<\/li>\n<li>forcediscover &#8211; re-discover a DC and not use a cached DC<\/li>\n<li>nextclosestsite &#8211; if there is no DC discovered in the local site, use the AD topology to find the closest DC in another site.<\/li>\n<li>service &#8211; the DC must support these services.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><br \/>\nAD PowerShell Module: Discover all Domain Controller in the domain:<\/span><\/p>\n<p><em>import-module activedirectory<\/em><br \/>\n<em>Get-ADDomainController -filter *<br \/>\n<\/em><\/p>\n<ul>\n<li>filter * &#8211; find all Domain Controllers<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><br \/>\nDiscover all Domain Controller in the domain using ADSI:<\/span><\/p>\n<p><em>[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">Discover all Global Catalogs in the forest using ADSI:<\/span><\/p>\n<p><em>[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().GlobalCatalogs<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">You can also use the Active Directory cmdlets to get computer information about Domain Controllers:<\/span><\/p>\n<p><em>import-module activedirectory<br \/>\nget-ADComputer -filter { PrimaryGroupID -eq \u201c516\u201d } -properties PrimaryGroupID<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are several different ways to find AD Domain Controllers (DCs). Here are a few: AD PowerShell Module: Discover the closest Domain Controller running the AD web services (support PowerShell AD cmdlets): import-module activedirectory Get-ADDomainController -discover -forcediscover -nextclosestsite -service ADWS discover &#8211; find a DC forcediscover &#8211; re-discover a DC and not use a cached &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=299\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,2],"tags":[20,155,154,101,379,575,372],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-powershell","category-technical-reference","tag-activedirectory","tag-dcdiscovery","tag-dclocator","tag-domaincontroller","tag-finddcs","tag-powershell","tag-primarygroupid","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299"}],"version-history":[{"count":1,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions\/300"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}