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

PowerShellHaving recently taken on a new client with a system that had been neglected somewhat I wanted to find out about the state of their user accounts.

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.

Get-ADUser on it’s own won’t give you any information. You need to give it a filter.Get-ADUserTry Get-ADUser -filter *.

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.Get-ADUser -filter *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. Get-ADUser -properties * 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

Get-ADUser 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

Get-ADUser properties scriptpath homedrive homedirectory formattable

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

get-aduser output

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.

Related Posts:

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

2. PowerShell: Get-ADUser to retrieve password last set and expiry information

3. PowerShell: How to add all users in an OU to a Security Group using Get-ADUser and Add-ADGroupMember

4. PowerShell: Get-ADUser to retrieve disabled user accounts

5. PowerShell: How to use Get-ADUser to list all recently created accounts (and recently changed accounts)

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.

If you found this post useful, please share!

    Related Posts

    14 thoughts on “PowerShell: Get-ADUser to retrieve logon scripts and home directories – Part 1

    1. Pingback: PowerShell: Identifying ActiveSync Devices with Get-ActiveSyncDevice for Exchange 2010 | Oxford SBS Guy

    2. Steve

      Very helpful! But there shouldn’t be a space between the “-” and “like” : where {$_.scriptpath –like “*bat*”}

      Reply
    3. FrankieR

      Thank you so much for sharing this information, which means knowledge to me.
      This is exactly what I need.
      Thanks again for sharing freely and so beautifully documented (with examples – screenshots – and everything).

      Reply
    4. John Hinde

      The best PS article I’ve read in ages, does exactly what it says on the tin. Takes baby steps for those just learning, doesn’t ever stray from the point, doesn’t get geeky or techie just plain simple PS info for those needing a hand in getting info out. I’m not a novice in PS but every now & again I need info on a command-let & what it can do outside the norm. This was a god send.

      Thankyou

      Reply

    Leave a Reply

    Your email address will not be published. Required fields are marked *