Attributes
Converting Manager attribute to show the manager’s email address.
@{Name="ManagerEmail";Expression={(get-aduser -property emailaddress $_.manager).emailaddress}}
Contractors & Admins
Searching for contractors based on a list of users provided. Filtering on Surname, DisplayName having (Contr) in it, and making sure they are enabled
$S = Get-Content -Path D:\psExports\LISTS\contr-sams.txt
$S | Foreach {
Get-ADUser -Filter {SN -eq $_ -and DisplayName -like "*(Contr)" -and Enabled -eq "true"} -Properties * | Select GivenName,SurName,mail, displayname
} | Export-Csv D:\psExports\ad\contr-stuff_3.csv -NoTypeInformation
Disabled Accounts
Search-ADAccount -AccountDisabled -UsersOnly | Select-Object Name, SamAccountName
Searching for accounts that have been disabled and left in an OU
Search-ADAccount –AccountDisabled –UsersOnly –SearchBase 'OU=ServiceAccounts,OU=Datacenter,DC=coolDomain,DC=COM' | `
Select Name,SamAccountName,Description,ExtensionAttribute14,Enabled
LockedOut Accounts
Search-ADAccount -LockedOut -UsersOnly | Select-Object Name, SamAccountName