{"id":702,"date":"2019-10-02T14:46:15","date_gmt":"2019-10-02T19:46:15","guid":{"rendered":"http:\/\/zewwy.ca\/?p=702"},"modified":"2019-10-02T14:46:15","modified_gmt":"2019-10-02T19:46:15","slug":"quick-managed-service-account-audit","status":"publish","type":"post","link":"https:\/\/zewwy.ca\/index.php\/2019\/10\/02\/quick-managed-service-account-audit\/","title":{"rendered":"Quick Managed Service Account Audit"},"content":{"rendered":"<p>First get the list of gMSAs from AD:<\/p>\n<pre>$gMSAlist = Get-ADServiceAccount -filter {samAccountName -like \"*\"}<\/pre>\n<p>Second Determine the systems allowed to use them:<\/p>\n<pre>ForEach ($gMSA in $gMSAlist) {(Get-ADServiceAccount $gMSA -properties *).PrincipalsAllowedToRetrieveManagedPassword}<\/pre>\n<p>Yay, we know who can use these accounts&#8230; but ARE they currently using it. If this returns a Group, look to see the systems in this group, else just access the system in question.<\/p>\n<p>Third, verify the account is in use by listing all the services on the system and the accounts used to run them:<\/p>\n<pre>Get-Service | Select -ExpandProperty Name | ForEach{(Get-WmiObject Win32_Service -Filter \"Name='$_'\") | Select Name, StartName}<\/pre>\n<p>The above command simply lists out all the services and the account they run under, it&#8217;s not optimal as it is slow, but it gets it all, and if you need a more readable version pipe it into Output-CSV, or apply a more granular filter on the result for the gMSAs in question.<\/p>\n<p>That&#8217;s about it, if you don&#8217;t see the gMSA listed on any service on the target machine, it&#8217;s rather safe to assume that the gMSA is not in use and can be safely removed from AD.<\/p>\n<pre>Remove-ADServiceAccount gMSAToBeRemoved<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First get the list of gMSAs from AD: $gMSAlist = Get-ADServiceAccount -filter {samAccountName -like &#8220;*&#8221;} Second Determine the systems allowed to use them: ForEach ($gMSA in $gMSAlist) {(Get-ADServiceAccount $gMSA -properties *).PrincipalsAllowedToRetrieveManagedPassword} Yay, we know who can use these accounts&#8230; but ARE they currently using it. If this returns a Group, look to see the systems &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zewwy.ca\/index.php\/2019\/10\/02\/quick-managed-service-account-audit\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Quick Managed Service Account Audit&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","footnotes":""},"categories":[12,8,197],"tags":[239,238],"class_list":["post-702","post","type-post","status-publish","format-standard","hentry","category-powershell","category-server-administration","category-windows","tag-audit","tag-gmsa"],"_links":{"self":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/comments?post=702"}],"version-history":[{"count":1,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/702\/revisions"}],"predecessor-version":[{"id":703,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/702\/revisions\/703"}],"wp:attachment":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/media?parent=702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/categories?post=702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/tags?post=702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}