although how would I export the results of the foreach loop /if statement to a csv? my idea is that once I export the results, I will then import that csv underneath the above code, and start my next bit of the script working off that csv of the affected users.
(untested)
This way you have your “results” in the two variables ADUserList and PWChangeList and you could export it or do more things as needed. Maybe like this:
You are going after this data repeatedly / dynamically from ADDS.
Why take the extra steps of serializing dynamic data to the drive, just to read it back in?
IMHO, that is a lot of unnecessary steps and you can simplify this down to a PSCustomObject for easier use / manipulation.
Again, PoSH is all about discovery, flexibility and choice. Not all of us will agree on the same things.
Anyways, this would be my approach at this use case. Always dynamic, no serialization to disk required, no extra variables.
Using object properties and as a function for, well, you know.
Function Get-PasswordLastSet
{
[CmdletBinding()]
[alias(‘pwls’)]