{"id":82,"date":"2011-10-26T14:53:00","date_gmt":"2011-10-26T14:53:00","guid":{"rendered":"\/post\/2011\/10\/26\/Check-server-accounts-in-Active-Directory.aspx"},"modified":"2011-10-26T14:53:00","modified_gmt":"2011-10-26T14:53:00","slug":"check-server-accounts-in-active-directory","status":"publish","type":"post","link":"https:\/\/www.vatland.no\/index.php\/check-server-accounts-in-active-directory\/","title":{"rendered":"Check server accounts in Active Directory."},"content":{"rendered":"<p>I made a simple powershell to list server accounts in AD, list versions and service pack level. It will also do a simple test-connection to see if it is alive (remember 2008 firewall will block icmp by default.<\/p>\n<p>Import-Module activedirectory<br \/>$htmlheader = &#8220;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;&#8221;<br \/>$trtdstart =&#8221;&lt;tr&gt;&lt;td&gt;&#8221;<br \/>$trtdstart3 =&#8221;&lt;tr bgcolor=#80ff80&gt;&lt;td&gt;&#8221;<br \/>$trtdstart1 =&#8221;&lt;tr bgcolor=#40FF00&gt;&lt;td&gt;&#8221;<br \/>$trtdstart2 =&#8221;&lt;tr bgcolor=#FF8080&gt;&lt;td&gt;&#8221;<br \/>$tdstart =&#8221;&lt;td&gt;&#8221;<br \/>$tdstartstop=&#8221;&lt;\/td&gt;&lt;td&gt;&#8221;<br \/>$tdend=&#8221;&lt;\/td&gt;&#8221;<br \/>$trtdend =&#8221;&lt;\/td&gt;&lt;\/tr&gt;&#8221;<br \/>$htmlfoot= &#8220;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;&#8221;<br \/>$counter = 1<br \/>$servere = get-adcomputer -filter {(Operatingsystem -like &#8220;*server*&#8221;)} -properties Name,OperatingSystem,OperatingSystemVersion,OperatingSystemServicePack -ResultSetSize 4000 -SearchScope subtree | Sort-Object -Property Name<br \/>$htmlheader | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm<br \/>$servere | ForEach-Object -process {<br \/>&nbsp;&nbsp; $gruppe= $null<br \/>&nbsp;&nbsp; $pingtest = Test-Connection -ComputerName $_.Name -WarningAction silentlycontinue -Count 1 -ErrorAction silentlycontinue<br \/>&nbsp;&nbsp; if ($_.OperatingSystemVersion -like &#8220;*6.1*&#8221;){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $trtdstart1 | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; } elseif ($_.OperatingSystemVersion -like &#8220;*6.0*&#8221;){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $trtdstart1 | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; } elseif ($_.OperatingSystemVersion -like &#8220;*5.2*&#8221;){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $trtdstart3 | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; } else <br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $trtdstart2 | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; $Counter| out-file -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $Counter=$Counter+1<br \/>$tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $_.Name| out-file -FilePath C:\\Powershell\\servers.htm -Append<br \/>$tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $_.OperatingSystem| out-file -FilePath C:\\Powershell\\servers.htm -Append<br \/>$tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $_.OperatingSystemVersion| out-file -FilePath C:\\Powershell\\servers.htm -Append<br \/>$tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $_.OperatingSystemServicePack | out-file -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $pingtest.IPV4Address.IPaddresstostring&nbsp; | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; $tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp; if ($pingtest) { &#8220;Echo reply&#8221; |Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append } else { &#8220;No reply&#8221; |Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append }<br \/>&nbsp;&nbsp;&nbsp; $tdstartstop | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>&nbsp;&nbsp;&nbsp;&nbsp; $trtdend | Out-File&nbsp; -FilePath C:\\Powershell\\servers.htm -Append<br \/>}<br \/>$htmlfooter | out-file -FilePath C:\\Powershell\\servers.htm -Append<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I made a simple powershell to list server accounts in AD, list versions and service pack level. It will also do a simple test-connection to see if it is alive (remember 2008 firewall will block icmp by default. Import-Module activedirectory$htmlheader = &#8220;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;&#8221;$trtdstart =&#8221;&lt;tr&gt;&lt;td&gt;&#8221;$trtdstart3 =&#8221;&lt;tr bgcolor=#80ff80&gt;&lt;td&gt;&#8221;$trtdstart1 =&#8221;&lt;tr bgcolor=#40FF00&gt;&lt;td&gt;&#8221;$trtdstart2 =&#8221;&lt;tr bgcolor=#FF8080&gt;&lt;td&gt;&#8221;$tdstart =&#8221;&lt;td&gt;&#8221;$tdstartstop=&#8221;&lt;\/td&gt;&lt;td&gt;&#8221;$tdend=&#8221;&lt;\/td&gt;&#8221;$trtdend =&#8221;&lt;\/td&gt;&lt;\/tr&gt;&#8221;$htmlfoot= &#8220;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;&#8221;$counter = 1$servere = &hellip; <a href=\"https:\/\/www.vatland.no\/index.php\/check-server-accounts-in-active-directory\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Check server accounts in Active Directory.<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"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":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[{"id":835,"url":"https:\/\/www.vatland.no\/index.php\/powershell-to-get-directaccess-connection-history\/","url_meta":{"origin":82,"position":0},"title":"Powershell to get DirectAccess connection history.","author":"Atle","date":"November 9, 2018","format":false,"excerpt":"This is a simple powershell to get data from the DirectAccess database. It reguired some serious Bing'ing (and google) to get the time field. You will have to configure reporting database in DirectAccess config. I used windows internal database. $server=\"\\\\.\\pipe\\MICROSOFT##WID\\tsql\\query\" $database=\"RaAcctDb\" #$table=\"connectiontable\" $table=\"sessiontable\" #$table=\"endpointsaccessedtable\" #$table=\"serverendpointtable\" $cs=\"server=$server;database=$database;Integrated Security=True;\" $connection=New-Object System.Data.SqlClient.SqlConnection $connection.ConnectionString=$cs\u2026","rel":"","context":"In \"DirectAccess\"","block_context":{"text":"DirectAccess","link":"https:\/\/www.vatland.no\/index.php\/tag\/directaccess\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":85,"url":"https:\/\/www.vatland.no\/index.php\/test-network-with-filecopy-and-powershell\/","url_meta":{"origin":82,"position":1},"title":"Test network with filecopy and Powershell","author":"Atle","date":"September 26, 2011","format":false,"excerpt":"Needed a way to test and time filecopy between servers using powershell. This is what I came up with. This example will use copy testfile.zip to server and time the progress. I used a file of 1.8 Gb. $servers=\"server1\",\"server2\",\"server3\",\"server4\",\"server5\",\"server6\"foreach($server in $Servers){if (!(test-path \\\\$server\\share\\temp)) {\u00a0\u00a0\u00a0 new-item -path \\\\$server\\share -name temp -ItemType\u2026","rel":"","context":"In &quot;Exchange&quot;","block_context":{"text":"Exchange","link":"https:\/\/www.vatland.no\/index.php\/category\/exchange\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":934,"url":"https:\/\/www.vatland.no\/index.php\/simple-powershell-mru-list\/","url_meta":{"origin":82,"position":2},"title":"Simple Powershell MRU list","author":"Atle","date":"December 23, 2019","format":false,"excerpt":"When using using my secret server powershell functions I got tired of constantly searching for secret ID's. I had to do a new search just because I could not remember the ID's. So I added some kind of MRU to my get-secretID function. This code block creates to classes mruitem\u2026","rel":"","context":"In &quot;Powershell&quot;","block_context":{"text":"Powershell","link":"https:\/\/www.vatland.no\/index.php\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70,"url":"https:\/\/www.vatland.no\/index.php\/exchange-powershell-max-quota-exceeded\/","url_meta":{"origin":82,"position":3},"title":"Exchange Powershell Max Quota exceeded.","author":"Atle","date":"May 27, 2012","format":false,"excerpt":"When doing some exchange powershell you would probably get this error or somthing like it sooner or later: Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. This user is allowed a maximum number of 18 concurrent shells, which has been\u2026","rel":"","context":"In &quot;Exchange&quot;","block_context":{"text":"Exchange","link":"https:\/\/www.vatland.no\/index.php\/category\/exchange\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":367,"url":"https:\/\/www.vatland.no\/index.php\/exchange-server-quarantined-a-mailbox\/","url_meta":{"origin":82,"position":4},"title":"Exchange server quarantined a mailbox.","author":"Atle","date":"November 11, 2014","format":false,"excerpt":"One user tried to run an attachment in a newly received email \u00a0. After this his mailbox became inaccessible. When he tried to access it\u00a0using OWA the familiar message appeared\u00a0: Something went wrong. My first thought was that the database was dismounted, but other mailboxes on the same database still\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"exchange","src":"https:\/\/i0.wp.com\/www.vatland.no\/wp-content\/uploads\/2014\/09\/exchange.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":361,"url":"https:\/\/www.vatland.no\/index.php\/lync-2013-management-shell-will-not-start\/","url_meta":{"origin":82,"position":5},"title":"Lync 2013 Management Shell will not start.","author":"Atle","date":"October 28, 2014","format":false,"excerpt":"If you are running Windows 2012R2 and install Lync server 2013 you might have problems starting Lync Management Shell. The Powershell Windows pops-up but no content appears. To get pass this I try to run PowerShell as Administrator and then run \"import-module Lync\"","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"Lyncserver","src":"https:\/\/i0.wp.com\/www.vatland.no\/wp-content\/uploads\/2014\/08\/Lyncserver-300x94.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":0,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}