Administration and Automation with Windows PowerShell

0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 42min

0 / 7 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

You need to sign up to get access!

Sign up to get full access to this course.

Sign up to access this lesson

Click here to sign up and get access to this lesson!

Saving Progress...

Generate a list of AD Users and their OU

In this lecture, we are going to use Windows PowerShell to generate a list of AD Users in their respective Organizational Units. This was a request by a student and I always love creating content that you guys want!

To get started, we will use the Get-ADUser command. We are required to pass a filter, and in this case I am going to use “*” with the quotes as my filter:

Get-ADUser -filter “*”

This returns all of the Active Directory users in our domain. We could use the “DistinguishedName” property to find their OU, but that isn’t the most human readable. There is another property that might work better called the “CanonicalName”. We can include this property by using the “-properties CanonicalName” parameter.

Get-ADUser -filter “*” -properties CanonicalName

We can see that this returns an easier-to-read path. So now we need to filter the results so we only get what information we want. I am going to pipe the above command to the select-object select the objects Name, SamAccountName, CanonicalName, and Enabled:

Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled

Now we have our list of users and their OU location. If we want to export this we can again pipe the output of this command to the Export-CSV command like so:

Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled | Export-CSV -Path “C:\ADUsers.csv”

The CSV file looks like this:

If you add -NoTypeInformation your CSV file will not include the first line:

Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled | Export-CSV -Path “C:\ADUsers.csv” -NoTypeInformation

Sign up to access the rest of this lesson

You must either log in or sign up to access this lesson.

Saving Progress...

0 0 votes
Lesson Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments