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=G ROUPA,OU=G roups,OU=H ERE,OU=THE RE,DC=ACME ,DC=com') -or
$_.memberof.contains('CN=G ROUPB,OU=G roups,OU=H ERE,OU=THE RE,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\THESEGR OUPS.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"
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=G
$_.memberof.contains('CN=G
} |
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\THESEGR
_______________
$UserExport = Get-ADUser -Filter * -SearchBase "OU=THISOU,OU=HERE,DC=ACME
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER