Below is the code I'm using to find users created date and last logon date which is then written to a .csv file.
$users=Get-ADuser -SearchBase "OU=testou1,dc=US,dc=ITOPS,dc=COM" -Filter * -properties samaccountname,lastlogondate,Created
$forloop = foreach($user in $users) {
echo $user.samaccountname
echo $user.created
echo $user.lastlogondate
}
$forloop | Out-file c:\bin\exporting.csv -Append
This code prints each item on a new line like this:
username
created date
last logon date
But I want it all on the same line with different columns:
username createdDate lastLogonDate