Powershell – How to get the “description” attribute of an OU in ActiveDirectory

active-directorypowershellwindows-server-2008-r2

I'm working on a set of script that will be used to migrate the users and structure from one active directory to another. For this, I'm using the Get-ADOrganizationalUnit commandlet to export the OUs like this:

Get-ADOrganizationalUnit -SearchBase $filterbase -filter * | export-csv $outcsv 

As it turns out, we have useful information stored in the "description" attribute of the source OUs. Unfortunately, it doesn't seem that this information is part of the data exported by the Get-ADOrganizationalUnit commandlet.

So, could anyone suggest a way in which I could get the same information from the source AD but including the Description ?

In truth, I can work very well if the only attributes I get back are DistinguishedName, name and description so if you have another way to list all OUs under a specific OU in AD that includes these attributes, (and can be piped to export-csv), it'll work as well.

Best Answer

Get-ADOrganizationalUnit -SearchBase $filterbase -filter * -Properties Description| export-csv $outcsv 

Should be what you're looking for. In almost all cases, if you want additional properties returned, then -Properties followed by a comma separated list of the additional properties is what you're looking for.

If you only want the three attributes that you mention in your question, then do something like:

Get-ADOrganizationalUnit -filter * -Properties Description | select-object name,distinguishedname,description | export-csv $outcsv