We help IT Professionals succeed at work.
Get Started

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

183 Views
1 Endorsement
Last Modified: 2015-08-05
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"
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE