PowerShell: Get-ADUser to retrieve logon scripts and home directories – Part 2

In Part 1 we looked at the Get-ADUser command, and used it to create a list of all users and display their homedrive, homedirectory and scriptpath.

In this post we’ll look at refining the results a little.

We’ll look at sorting the results, only returning results for user accounts that have a login script, and export them to CSV, which is much more useful than exporting the results to a text file.
So, the final command we ended Part 1 with was the following and it returned a text file to us with a list of all users as seen in the image below (I’ve added a few more parameters to users in this example.

Many thanks. This helped a lot.
I’m within a AD forest, so perhaps those of you who are in the same situation can benefit from this (I don’t have the home drive in here):
Get-ADUser -SearchBase “ou=Users,ou=myorg,dc=mydomain,dc=com” -Filter * -properties scriptpath, homedirectory | sort-object scriptpath | select-object Name, scriptpath, homedirectory | Export-csv -path c:\temp\UsersAndtheirScripts.csv