I have a Windows 2008 R2 environment
I need a powershell script to find and process stale user accounts. Here are the conditions I want to meet
1. Look for user objects in a particular OU (No one is this OU should have 'PasswordNeverExpires' set)
2. Identify users whose lastLogonTimeStamp is greater than 105 days (this value may be null) OR pwdLastSet is greater
than 91 days (this value may be null), exclude accounts that have a particular prefix; i.e z-
3. Capture and export these accounts to a path\filenaname.csv with headers of
samAccountName,givenName,sn,lastLogonTimeStamp,pwsLastSet (don't know if headers in file can be more readable,
like LogonID,First Name, Last Name, Last Logon, Pwd Last Set - not crucial to this effort)
4. Import the csv file sorting by samAccountName and do the following:
a. Disable the account
b. Update the Description field to some text; i.e "Disabled by automated process on $date"
c. Move the account to a holding OU
5. Finally email the CSV file to whomever (there is an smtp server) with subject like; i.e. 'Disabled user accounts for 90+ day non-use'
Clearly I'm a newbie to PS.