how to Find Active Directory Service Accounts with Powershell script –
Run the Following PS Command :
1 |
Get-ADComputerServiceAccount $env:COMPUTERNAME |
you can change the computer name as well to find MSA on remote server.
now what about get the Groups of the user is belong to ?>
1 |
$Group = Get-ADServiceAccount $Account -Properties MemberOf | select -ExpandProperty MemberOf |
view it all nicely 🙂 –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
###get MSA Account on server and check on which GROUP it Belong to### Write-Host "Checking for MSA Accounts And Group Mambership for MSA Account" -BackgroundColor Black -ForegroundColor White $MSA = Get-ADComputerServiceAccount $env:COMPUTERNAME $ServiceAccounts = @() ForEach ($m in $MSA) { $Account = $m.name $Group = Get-ADServiceAccount $Account -Properties MemberOf | select -ExpandProperty MemberOf $ServiceAccount = New-Object System.Object $ServiceAccount | Add-Member -Type NoteProperty -Name Account -Value $m.Name $ServiceAccount | Add-Member -Type NoteProperty -Name Group -Value $Group # # $ServiceAccounts += $ServiceAccount } if ($ServiceAccounts.Count -eq 0) { Write-Host "NT Services Not found with MSA Installed on This Server" -BackgroundColor Yellow -ForegroundColor Red } elseif ($ServiceAccounts.Count -gt 0) { $ServiceAccounts | fl } else { Write-Host "Installed Service Accounts / MSA" -BackgroundColor Black -ForegroundColor White } |
(Visited 3,265 times, 1 visits today)