{"id":131,"date":"2014-07-23T15:17:53","date_gmt":"2014-07-23T19:17:53","guid":{"rendered":"http:\/\/blog.metcorp.org\/?p=131"},"modified":"2014-07-24T20:17:34","modified_gmt":"2014-07-25T00:17:34","slug":"powershell-get-all-active-directory-sites-based-on-domain","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=131","title":{"rendered":"PowerShell: Get all Active Directory Sites based on Domain"},"content":{"rendered":"<p>Get all Active Directory Sites based on Domain.<\/p>\n<p>&nbsp;<\/p>\n<div>\n<div>$DomainSiteFilter = &#8220;DomainA&#8221;<\/div>\n<div><\/div>\n<div>Write-Output &#8220;Get AD Site List `r&#8221;<\/div>\n<div>$ADSites = [System.DirectoryServices.<wbr \/>ActiveDirectory.Forest]::<wbr \/>GetCurrentForest().Sites<\/div>\n<div>[int]$ADSitesCount = $ADSites.Count<\/div>\n<div>Write-Output &#8220;There are $ADSitesCount AD Sites in the forest `r&#8221;<\/div>\n<div><\/div>\n<div>$DomainADSites = $ADSites | where {$_.Domains -like &#8220;*$DomainSiteFilter*&#8221;} | sort-object name<\/div>\n<div>[int]$DomainADSitesCount = $DomainADSites.Count<\/div>\n<div>Write-Output &#8220;There are $DomainADSitesCount AD Sites matching the domain site filter: $DomainSiteFilter \u00a0`r&#8221;<\/div>\n<\/div>\n<div><\/div>\n<p>$DomainADSites | select name | ft -auto<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get all Active Directory Sites based on Domain. &nbsp; $DomainSiteFilter = &#8220;DomainA&#8221; Write-Output &#8220;Get AD Site List `r&#8221; $ADSites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites [int]$ADSitesCount = $ADSites.Count Write-Output &#8220;There are $ADSitesCount AD Sites in the forest `r&#8221; $DomainADSites = $ADSites | where {$_.Domains -like &#8220;*$DomainSiteFilter*&#8221;} | sort-object name [int]$DomainADSitesCount = $DomainADSites.Count Write-Output &#8220;There are $DomainADSitesCount AD Sites matching &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=131\">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],"tags":[52,575],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-activedirectorysites","tag-powershell","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/131","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=131"}],"version-history":[{"count":1,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions\/132"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}