Avatar of deniecegreenwood
deniecegreenwood
 asked on

How to combine 2 "get-aduser" commands into one report

Hello.  I have 2 pieces of information that I need to combine into one report.
First: list members of GROUPA and GROUPB
Second: list users in OU=THISOU.

As you can see, everything from "Select-Object" and down is the same for both.  I believe I just need to find how to combine the two Get-ADUser commands.  Thanks in Advance.

$UserExport =  Get-ADUser -Filter * -Properties memberOf | `
Where-Object {
    $_.memberof.contains('CN=GROUPA,OU=Groups,OU=HERE,OU=THERE,DC=ACME,DC=com') -or
    $_.memberof.contains('CN=GROUPB,OU=Groups,OU=HERE,OU=THERE,DC=ACME,DC=com')
    } |
    Select-Object -Property @{n="ColumnA"; e={"CUSTOM COLUMN"}}, SamAccountName, Surname, GivenName |
    sort SamAccountName |
  ConvertTo-CSV -NoTypeInformation |
  Select-object -Skip 1 |
  Set-Content -Path "C:\Scripts\Output\THESEGROUPS.csv"

_______________


$UserExport =  Get-ADUser -Filter * -SearchBase "OU=THISOU,OU=HERE,DC=ACME,DC=com" |
  Select-Object -Property @{n="ColumnA"; e={"CUSTOM COLUMN"}}, SamAccountName, Surname, GivenName |
  sort SamAccountName |
  ConvertTo-CSV -NoTypeInformation |
  Select-object -Skip 1 |
  Set-Content -Path "C:\Scripts\Output\THISOU.csv"
PowershellActive Directory

Avatar of undefined
Last Comment
deniecegreenwood

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Brian Scholer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
deniecegreenwood

ASKER
Outstanding!  Thank you so very much.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23