We help IT Professionals succeed at work.

Need to export the list of AD users with below attrubutes

SAM IT
SAM IT asked
on
410 Views
Last Modified: 2017-04-19
Below script export the created and disabled AD users for last one day. When remove the filter and run the script to export all the AD users using same attributes its not working, Thanks in advance

$FilterDate = (Get-Date).AddDays(-1).Date
$NetBIOSDomain = (Get-ADDomain).NetBIOSName
Get-ADUser -Filter {(whenCreated -ge $FilterDate)} -Property UserPrincipalName, Enabled, Mail, l, physicalDeliveryOfficeName, telephoneNumber, extensionAttribute9, State, c, co, msExchRecipientTypeDetails, co, Manager, whenCreated, whenChanged |
	Select-Object -Property SamAccountName, @{n='NTAccountName'; e={"$($NetBIOSDomain)\$($_.SamAccountName)"}}, UserPrincipalName, Enabled, WhenCreated, WhenChanged, extensionAttribute9, State, c, co, msExchRecipientTypeDetails, Mail, @{n='City'; e={$_.l}}, physicalDeliveryOfficeName, TelephoneNumber, @{n='Country'; e={$_.co}}, Manager, DistinguishedName, @{n='ParentContainer'; e={($_.DistinguishedName -split '(?<!\\),', 2)[1]}} | Export-Csv C:\out.csv

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
"Filter" is a mandatory argument if you're not querying using -Identity; to get all users, use -Filter *
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.