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"