1

I read out all AD-User out of different OUs.

I Need the function Append but if i do it with this it doesn't overwrite the CSV Export if i run the Script again.

If i do it without the function Append it overwrites all other OUs and all I see in the End is the last OU.

My source code:

Foreach($OU in $OUs) {
    Get-ADUser -Filter * -SearchBase $OU -Properties $Properties| Select-Object $Properties |export-Csv -Append $Export -Encoding  UTF8
}
Bsquare ℬℬ
  • 4,423
  • 11
  • 24
  • 44
Naimad
  • 39
  • 5
  • I’ve just [edited your question](https://stackoverflow.com/help/editing), improving either its formatting, or [its quality](https://stackoverflow.blog/2011/02/05/suggested-edits-and-edit-review/) to help people understanding your question, and to help you to get an appropriate answer. But you still need to add further information for your question to become solvable. – Bsquare ℬℬ Dec 11 '18 at 11:13

1 Answers1

1

Collect your AD-users in a variable and convert them all together instead of writing to the file Foreach ($OU in $OUs).

Foreach ($OU in $OUs) {
    $CollectedUsers += Get-ADUser -Filter * -SearchBase $OU -Properties $Properties| Select-Object $Properties 
}
$CollectedUsers | export-Csv $Export -Encoding UTF8
Razorfen
  • 423
  • 4
  • 12
T-Me
  • 1,814
  • 1
  • 9
  • 22