Extract "pwdLastSet, Password expires, Password changeable, Password required, User may change password" property for all Staff OU users

Billvel 21 Reputation points
2021-05-15T10:59:32.427+00:00

Hi Guys,

Trying to Extract "pwdLastSet, Password expires, Password changeable, Password required, User may change password" property for all Staff OU users and export to csv.

Any advice would be greatly appreciated. Thank you

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2021-05-15T11:31:56.597+00:00

    Hi @Billvel ,

    the command Get-AdUser should be helpful to get all users of OU:
    https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-aduser?view=windowsserver2019-ps#example-1--get-all-of-the-users-in-a-container

    With the parameter -Properties * you will get all properties of a user.

    Here is a list of all Ad user properties returned by Get-ADUser:
    https://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx

    With the Select-Object command you can filter the properties.

    The script could look like this (not tested by myself):

    $users = Get-ADUser -Filter * -SearchBase "OU=STAFF,DC=TEST,DC=LOCAL" | Select-Object <propertyname1>,<propertyname2>,<....>  
    $users | Export-Csv -Path "C:\temp\yourcsvfile.csv" -Encoding utf8 -Delimiter ","  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments