Few comments:
- You don't need to do two requests to get the members and their attributes. You can pipe the first one with the second. The way you do it will only get teh direct members of the groups and not its nested members (unless that's what you want and in that case you could stick with that I guess).
- You don't need to use quotes in the list of properties.
- You don't need to expand any properties. It is failing at the moment because you can expand only one property. But in your case, since you are exporting stuff to a a file, you don't need to do that. And you could also export it in a more useful format such as csv.
So here is a revisited version of your script:
$members = Get-ADGroupMember -Identity "test_test_test" -Recursive | Get-ADUser -Properties samaccountname,enabled,passwordexpired,lockedout,whenchanged
$members | Export-Csv userids_final.csv -NoTypeInformation
You could remove the -Recursive
if you wanted only the direct group membership. And you could also do that in one line.