New to using Powershell, so I apologize for any noobness that I show.
I'm trying to extract user names, active status, Expiration Dates and Titles from Active Directory.
My Powershell command is:
Get-ADUser -Filter * -SearchBase "DC=XXX,DC=XXXX" |
Select-Object Name, GivenName, Surname, SamAccountName, DistinguishedName, enabled, Title, AccountExpirationDate |
Export-Csv -Path c:\users\myname\ADUsersWithExpirationDate.csv
The query runs successfully, but does not ever show a Title or Expiration Date even though some user accounts have either or both values in AD. Also status (Enabled) does not always populate: the returned values are True, False, or null. All of the Nulls (that I've checked) are active user accounts, but appear to be in non-standard OU's (Admins for example).
Any insight or recommendations are very welcome.
Thanks in advance.
CodePudding user response:
By default the AD cmdlets don't return all the attributes. You need to use the -Properties
parameter to add the AccountExpirationDate and Title attributes to the query. Your command should look something like:
Get-ADUser -Filter * -SearchBase "DC=XXX,DC=XXXX" -Properties 'Title','AccountExpirationDate' |
Select-Object Name, GivenName, Surname, SamAccountName, DistinguishedName, enabled, Title, AccountExpirationDate |
Export-Csv -Path c:\users\myname\ADUsersWithExpirationDate.csv