Active Directory computer information export

I am trying to make a script that will pull information from computers in an AD OU

It will pull the name, description and what security groups each computer belongs to I.e

computer001 - this is pc 001 - bitlocker clients, cm_etcgroup

It works fine with an OU only with computers, however, if an OU contains security groups, or other objects it wont pull the member of group information

Any help would be appreciated

Get-ADComputer -SearchBase "OU=myOU" -server "servername" -filter * -Properties Description, MemberOf, CanonicalName | 
Select-Object Name, Description, @{Name="MemberOfGroups"; Expression={($_.MemberOf | ForEach-Object {(Get-ADGroup $_).Name})}} | 
Export-Csv -Path "C:\" -NoTypeInformation

If your asking why it won’t pull info for other object types besides computers, that would be because you’re using Get-ADCOMPUTER. Use Get-ADObject instead.

1 Like

Thanks for the reply

I tried changing to Get-ADObject and it gives the same results

You may elaborate a little more detailed what you’re actually trying to do. It seems like you’re expecting something what’s either not possible or at least very unlikely. :wink:

Sure

I need to pull the following information from certain OUs in our active directory, namely

Name of the object (mainly computers)
Description of the object
The names of groups those objects are members of (Properties > Member of)

If i run the script on an OU with only computers it seems to work fine, however, the OUs i need info from have a mixture of global security groups, computers and another OU

I have attached some pictures for more clarity



Honestly, you haven’t cleared it up at all. You’re saying the script will pull all the info you desire properly if only computers list in the OU, otherwise it will only pull the name and description if there are other objects in the OU? Your “MemberofGroups” property just comes back blank? That makes zero sense.

Apologies if I did not make sense

I eventually got it working

$csvPath = ""
$ouDN = ""
$svr = ""

$members = Get-ADComputer -SearchBase $ouDN -server $svr -Filter {ObjectClass -eq "computer"} -Properties Name, Description, memberOf

$members | Select-Object Name, Description, @{Name="MemberOf";Expression={$_.memberOf -join "; "}} | Export-Csv -Path $csvPath -NoTypeInformation

This outputs only name, description and member of computers in the OU

OK. And what would you expect? It might become clearer if you showed an example of the expected output.

I really need to word my replies better :rofl:

I got what I needed to work

Example

So all good now, i appreciate everyone’s help :smiley:

Amen. :pray:t3:

Great. :+1:t3: