Link to home
Start Free TrialLog in
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"
ASKER CERTIFIED SOLUTION
Avatar of Brian Scholer
Brian Scholer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deniecegreenwood
deniecegreenwood

ASKER

Outstanding!  Thank you so very much.