{"id":199,"date":"2007-07-14T11:11:39","date_gmt":"2007-07-14T09:11:39","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=199"},"modified":"2007-07-14T12:06:03","modified_gmt":"2007-07-14T10:06:03","slug":"script-check-account-status","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=199","title":{"rendered":"Script: Check Account Status"},"content":{"rendered":"<p>This is\u00c2\u00a0two simple script to check if a account is enable or disable. If enable, a local event will be created. In this example I check if the Guest account is enable, if it is a local event will be generated. You can then pickup that event with a event rule.<\/p>\n<p><code>strUser = \"LDAP:\/\/cn=Guest,cn=Users,dc=contoso,dc=internal\"Set objUser = GetObject _<br \/>\n\u00c2\u00a0 (strUser)<br \/>\n\u00c2\u00a0<br \/>\nIf objUser.AccountDisabled = FALSE Then<br \/>\n\u00c2\u00a0Const EVENT_WARNING = 2<br \/>\n\u00c2\u00a0Set objShell = Wscript.CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0objShell.LogEvent EVENT_WARNING, _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \"The account \" & strUser & \" is no longer disable. Please investigate.\"<br \/>\nEnd If<\/code><\/p>\n<p>If you want to check all accounts in a OU you can use the this script. It will check a OU named Service_accounts<br \/>\n<code>set objOU = GetObject _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 (\"LDAP:\/\/OU=Service_Accounts,DC=contoso,DC=internal\")<br \/>\n\u00c2\u00a0<br \/>\nObjOU.Filter= Array(\"user\")<\/code><code>For Each objUser in ObjOU<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0strUser = \"LDAP:\/\/\" + objUser.distinguishedName<br \/>\n\u00c2\u00a0Set objUser = GetObject _<br \/>\n\u00c2\u00a0\u00c2\u00a0 (strUser)<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0If objUser.AccountDisabled = FALSE Then<br \/>\n\u00c2\u00a0Const EVENT_WARNING = 2<br \/>\n\u00c2\u00a0Set objShell = Wscript.CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0objShell.LogEvent EVENT_WARNING, _<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \"The account \" & strUser & \" is no longer disable. Please investigate.\"<br \/>\nEnd If<br \/>\nNext<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is\u00c2\u00a0two simple script to check if a account is enable or disable. If enable, a local event will be created. In this example I check if the Guest account is enable, if it is a local event will be generated. You can then pickup that event with a event rule. strUser = &#8220;LDAP:\/\/cn=Guest,cn=Users,dc=contoso,dc=internal&#8221;Set objUser &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=199\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[2,13,19],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/199"}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199"}],"version-history":[{"count":0,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}