I’d already looked at a couple of users at random and noticed some users had logon scripts while others didn’t, and some users had home drives while others didn’t.
Although the organisation wasn’t large, they had more than enough user accounts that I didn’t want to manually check every one. So i turned to PowerShell’s Get-ADUser command.
Until recently I’ve not given PowerShell much time. But since using Windows Server 2012 I’ve found myself using PowerShell more and more, and I’m starting to like it!
Right, on with a quick tutorial of Get-ADUser.The following screenshots are taken from my Windows Server 2012 demo lab.
This will return all the users in the domain. But as you can see from the format it isn’t really that useful to us at the moment as it isn’t showing any logon script information or home drives.Next lets single out an individual user and see what information we can see.
Try Get-ADuser username -properties *.
This will show you all the properties associated with the user. Now we can see a list of all the properties associated with a user account, we can start to format the Get-ADUser command to just show us the information we require.
Try Get-ADUser username Joe.bloggs -properties scriptpath, homedrive, homedirectory
We can now see the information we want for a single user, but a table of users would be useful…
Try Get-ADUser -filter * -properties scriptpath, homedrive, homedirectory | ft Name, scriptpath, homedrive, homedirectory
Now the last step is to output the table to a file so we can use it in our documentation.
Try Get-ADUser -filter * -properties scriptpath, homedrive, homedirectory | ft Name, scriptpath, homedrive, homedirectory > C:\temp\users.txt
By taking a look at the properties of an individual user you can build a table with any combination of user properties you are interested in.
The Microsoft Technet reference can be found here: http://technet.microsoft.com/en-us/library/ee617241.aspx
In Part two of this post we’ll look at Sorting tables and Exporting to CSV and picking out selecting data using parameters.
This is one of my most popular posts, so if you found it useful please share with your colleagues, like or leave a comment. Thanks, Carl.