Power Shell command for Users in AD

I need to generate report  in power shell for all users in OU with password expiration date and latest date password change .
Policy to change password is 45 days

I have OU for all regions as
OU = region1 then
OU =Country x
then Users , workstations and servers
I know Get-ADUser  is to get al require information but I need to add parameters as filter to get require information in report .
can you help
salmaaloufAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Are you wanting to know how to export the gathered information into a report or how to limit the Get-ADUser cmdlet to just the OUs you want?

If you're wanting to limit it, you can specify the -searchbase as the OU you want to be the root of your search.
0
salmaaloufAuthor Commented:
I want to limit the Get-ADUser cmdlet to just the OUs I want , can you send me the full command
0
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Sure, the command is:

Get-ADUser -Filter * -Searchbase "<dn of OU>"

Open in new window

0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

salmaaloufAuthor Commented:
IF I want to add two OU  it should be like that  :

Get-ADUser -Filter * -Searchbase "<OU = region1 ,OU =Country x>"

and what about password expiration date and latest date password change . what parameters should I add .
0
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
So let's say you have the following OUs you want to get the info from:

- domain.com\APAC\JP
- domain.com\EMEA\DE

You would want the following:

$ADUsers = Get-ADUser -Filter * -SearchBase "OU=JP,OU=APAC,DC=domain,DC=com" -Properties msDS-UserPasswordExpiryTimeComputed,PasswordLastSet
$ADUsers += Get-ADUser -Filter * -SearchBase "OU=DE,OU=EMEA,DC=domain,DC=com" -Properties msDS-UserPasswordExpiryTimeComputed,PasswordLastSet

$ADUsers | select name.PasswordLastSet,@{name='PasswordExpires';Expression={[datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}}

Open in new window

0
salmaaloufAuthor Commented:
I run  script but output of name and password last set is empty , can you check please
0
salmaaloufAuthor Commented:
Did take a look for screen shot I attached
0
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Don't see the screenshot but I do see the issue. I typed a period (.) instead of a comma (,) in the select statement. Here's the corrected script:

$ADUsers = Get-ADUser -Filter * -SearchBase "OU=JP,OU=APAC,DC=domain,DC=com" -Properties msDS-UserPasswordExpiryTimeComputed,PasswordLastSet
$ADUsers += Get-ADUser -Filter * -SearchBase "OU=DE,OU=EMEA,DC=domain,DC=com" -Properties msDS-UserPasswordExpiryTimeComputed,PasswordLastSet

$ADUsers | select name,PasswordLastSet,@{name='PasswordExpires';Expression={[datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}}

Open in new window

0
salmaaloufAuthor Commented:
That work perfectly  , is there is a way to export to excel file
0
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Sure, just pipe it to Export-CSV:

[code]
$ADUsers | select name,PasswordLastSet,@{name='PasswordExpires';Expression={[datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}} | Export-CSV C:\output.csv [code]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
salmaaloufAuthor Commented:
Very good support and response time .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.