{"id":526,"date":"2014-06-25T13:36:18","date_gmt":"2014-06-25T13:36:18","guid":{"rendered":"http:\/\/giraffeit.com\/?p=526"},"modified":"2014-06-25T13:36:18","modified_gmt":"2014-06-25T13:36:18","slug":"psserver","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2014\/06\/25\/psserver\/","title":{"rendered":"Powershell : Find all servers in a domain"},"content":{"rendered":"<p>This code will find all servers in a domain and return its canonical location<\/p>\n<p>&nbsp;<\/p>\n<p>$objSearcher = New-Object System.DirectoryServices.DirectorySearcher<br \/>\n$objSearcher.Filter = &#8216;(OperatingSystem=Window*Server*)&#8217;<br \/>\n&#8220;Name&#8221;,&#8221;canonicalname&#8221;,&#8221;distinguishedname&#8221; | Foreach-Object {$null = $objSearcher.PropertiesToLoad.Add($_) }<br \/>\n$objSearcher.FindAll() | Select-Object @{n=&#8217;Name&#8217;;e={$_.properties[&#8216;name&#8217;]}},@{n=&#8217;ParentOU&#8217;;e={$_.properties[&#8216;distinguishedname&#8217;] -replace &#8216;^[^,]+,&#8217;}} | ft -autosize<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This code will find all servers in a domain and return its canonical location &nbsp; $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.Filter = &#8216;(OperatingSystem=Window*Server*)&#8217; &#8220;Name&#8221;,&#8221;canonicalname&#8221;,&#8221;distinguishedname&#8221; | Foreach-Object {$null = $objSearcher.PropertiesToLoad.Add($_) } $objSearcher.FindAll() | Select-Object @{n=&#8217;Name&#8217;;e={$_.properties[&#8216;name&#8217;]}},@{n=&#8217;ParentOU&#8217;;e={$_.properties[&#8216;distinguishedname&#8217;] -replace &#8216;^[^,]+,&#8217;}} | ft -autosize<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=526"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}