0

I am very new to Powershell and I'm trying to export three attributes found in multiple groups. Lets say these are Attribute A, Attribute B, and Attribute C.

Attribute A and B are present in all groups returned by the Get-ADGroup query I've written. However, Attribute C is only present in 1/3 of the groups, and for the remainder of these groups the Attribute C field is 'null'.

When I try to export this data to excel (using Export-Csv), Attribute A and B are correctly exported as columns, however Attribute C is not there. How do I include Attribute C as a column for the groups that have that field filled in, when exporting this query results as csv?

The query that I am using is:

Get-ADGroup -LDAPFilter "(name=IT-*)" -SearchScope Subtree -SearchBase "DC=KRFT, DC=Net" 
-Properties Attribute A, Attribute B, Attribute C | Export-Csv 
"C:\Users\user1\Desktop\Powershell\groups.csv" 

Thanks :)

Devin S
  • 135
  • 1
  • 12
  • If I understand correctly, you can force column for AttributeC by inserting `| Select-Object Attribute A, Attribute B, Attribute C` before the Export-Csv cmdlet. Unsure of course whether that attribute exists.. Also, you show a searchbase with spaces that should not be there.. – Theo Mar 18 '20 at 10:34
  • I have also posted this as answer, so you can accept it by clicking the checkmark icon next to it. That way, other users with a similar questionwill be able to find it more easily. – Theo Mar 18 '20 at 11:19
  • Does this answer your question? [Not all properties displayed](https://stackoverflow.com/questions/44428189/not-all-properties-displayed) – iRon Mar 18 '20 at 13:46

1 Answers1

0

As commented, you can force the columns that appear in the output CSV by inserting a Select-Object before the Export-Csv cmdlet. That way, all items written will have this column, empty or not:

Get-ADGroup -LDAPFilter "(name=IT-*)" -SearchScope Subtree -SearchBase "DC=KRFT,DC=Net" -Properties AttributeA, AttributeB, AttributeC | 
    Select-Object AttributeA, AttributeB, AttributeC | Export-Csv "C:\Users\user1\Desktop\Powershell\groups.csv" 
Theo
  • 57,719
  • 8
  • 24
  • 41