-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAD_User_Audit.ps1
24 lines (20 loc) · 1.32 KB
/
AD_User_Audit.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
######################################################################
# Title: AD_User_Audit_v1 #
# Author: Aaron J. Katz #
# Description: Obtain AD information about users in selected domains #
# Version: 1.0.1 #
# Changelog: #
# * Added IsServiceAccount column. Determine if service account by #
# checking if the phrase "service account" is in the desc. #
######################################################################
import-module activedirectory
$servers = "" # Comma-separated list of domain controllers, one per domain
$output = @()
foreach($server in $servers){
$output += Get-ADUser -Properties * -Filter * -Server $server | Select @{Name='Server';Expression={$server}}, @{Name='Domain';Expression={(Get-ADDomain (($_.DistinguishedName.Split(",") | ? {$_ -like "DC=*"}) -join ",")).NetBIOSName}},
‘Name’,’DisplayName’,’SamAccountName’,'Enabled','PasswordLastSet','PasswordNeverExpires',
@{Name='IsServiceAccount';Expression={$_.Description -like "*service account*"}},
@{Name='IsDomainOrEnterpriseOrSchemaAdmin';Expression={[string]::join(";",($_.MemberOf)) -match "(Domain Admins|Enterprise Admins|Schema Admins)"}},
@{Name=’MemberOf';Expression={$_.MemberOf -join ';'}}
}
$output | export-csv -NoTypeInformation .\adoutput.csv