'user1','user2' | foreach-object {
get-aduser -identity $_ -Properties * |
select name,DisplayName,samaccountname,enabled, accountexpirationdate,whenchanged }| ft
name DisplayName samaccountname enabled accountexpirationdate whenchanged
---- ----------- -------------- ------- --------------------- -----------
user1, MyName, user1 False 11-04-2023 00:00:00 11-04-2023 00:42:21
user2, MyName, user2 False 11-04-2023 00:00:00 11-04-2023 00:42:21
I want to have all the date fields formatted as shortdates
I have tried to add -format string to each datefield without success
This should do what you're looking for
where you can tweak the exact date format being returned by changing the format bit in each
entry as needed.