{"id":230,"date":"2010-02-24T22:24:25","date_gmt":"2010-02-25T03:24:25","guid":{"rendered":"http:\/\/nukeitmike.com\/blog\/2010\/02\/24\/servers-in-domain-2\/%20"},"modified":"2010-02-24T22:24:25","modified_gmt":"2010-02-25T03:24:25","slug":"servers-in-domain","status":"publish","type":"post","link":"https:\/\/blog.nukeitmike.com\/index.php\/2010\/02\/24\/servers-in-domain\/","title":{"rendered":"Servers in Domain"},"content":{"rendered":"<p>At some point, I had a desire to list all the computer accounts for any server OS in Active Directory.\u00a0 I am pretty sure that I did a search and found the script below, but I don\u2019t remember where, so whoever wrote it doesn\u2019t get credit this time\u2026<\/p>\n<blockquote><p>$strCategory = &#8220;computer&#8221;<br \/>\n$strOperatingSystem = &#8220;Windows*Server*&#8221;<\/p>\n<p>$objDomain = New-Object System.DirectoryServices.DirectoryEntry<\/p>\n<p>$objSearcher = New-Object System.DirectoryServices.DirectorySearcher<br \/>\n$objSearcher.SearchRoot = $objDomain<\/p>\n<p>$objSearcher.Filter = (&#8220;OperatingSystem=$strOperatingSystem&#8221;)<\/p>\n<p>$colProplist = &#8220;name&#8221;<br \/>\nforeach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}<\/p>\n<p>$colResults = $objSearcher.FindAll()<br \/>\nWrite-Host $colResults.count<br \/>\nforeach ($objResult in $colResults)<br \/>\n\u00a0\u00a0\u00a0 {<br \/>\n\u00a0\u00a0\u00a0 $objComputer = $objResult.Properties;<br \/>\n\u00a0\u00a0\u00a0 $objComputer.name<br \/>\n\u00a0\u00a0\u00a0 }<\/p><\/blockquote>\n<p>If you change the $strOperatingSystem = \u201cWindows*Server*\u201d to something like $strOperatingSystem = \u201cWindows*\u201d\u00a0 it will return all computer accounts that have \u201cWindows\u201d in the Name field on the Operating System tab of the properties of the AD object:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/blog.nukeitmike.com\/wp-content\/uploads\/2010\/02\/image.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"https:\/\/i0.wp.com\/blog.nukeitmike.com\/wp-content\/uploads\/2010\/02\/image_thumb.png?resize=644%2C263&#038;ssl=1\" border=\"0\" alt=\"image\" width=\"644\" height=\"263\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>At some point, I had a desire to list all the computer accounts for any server OS in Active Directory.\u00a0 I am pretty sure that I did a search and found the script below, but I don\u2019t remember where, so whoever wrote it doesn\u2019t get credit this time\u2026 $strCategory = &#8220;computer&#8221; $strOperatingSystem = &#8220;Windows*Server*&#8221; $objDomain&hellip; <a class=\"more-link\" href=\"https:\/\/blog.nukeitmike.com\/index.php\/2010\/02\/24\/servers-in-domain\/\">Continue reading <span class=\"screen-reader-text\">Servers in Domain<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[25],"tags":[44,135,154],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-active-directory","tag-powershell","tag-scripting","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pcW544-3I","_links":{"self":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":0,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}