Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

get-aduser for different properties and combine them into one result file

$
0
0

hello. thanks for the time and effort.

i have 2 powershell commands that need to combined into one result. first command gets all ad user who have an employeeID and exports their details out such as department manager location...etc.  the 2nd command is only to export contractors who do not have an employeeID but rather belong to a specific OU.

ONE:

get-aduser -filter * -properties * | where-object {-not[string]::IsNullOrEmpty($_.employeeID)} | select employeeID,@{n="first name";e={$_."GivenName"}},@{n="last name";e={$_."Surname"}},title,@{n="Manager";e={(get-aduser -identity $_.Manager -properties DisplayName).DisplayName}},@{n="UserName";e={$_."samaccountname"}},@{n="Work Email";e={$_."Emailaddress"}},@{n="Work Phone";e={$_."OfficePhone"}},{n="Work Fax";e={$_."Fax"}},@{n="Location Description";e={$_."ExtensionAttribute2"}},@{n="Work Location";e={$_."City"}},@{n="Cube Location";e={$_."Office"}},@{n="Department Number";e={$_."EmployeeNumber"}},@{n="Space Cost Center Depth 0";e={$_."EmployeeNumber"}},@{n="Space Cost Center Depth 1";e={$_."Department"}},@{n="Space Cost Center Depth 3";e={(Get-ADUser -Identity $_.Manager -properties DisplayName).DisplayName}} | export-csv c:\results\employees.csv -notype

TWO:

get-aduser -searchbase "ou=contractors,dc=corp,dc=com" -properties * | select employeeID,@{n="first name";e={$_."GivenName"}},@{n="last name";e={$_."Surname"}},title,@{n="Manager";e={(get-aduser -identity $_.Manager -properties DisplayName).DisplayName}},@{n="UserName";e={$_."samaccountname"}},@{n="Work Email";e={$_."Emailaddress"}},@{n="Work Phone";e={$_."OfficePhone"}},{n="Work Fax";e={$_."Fax"}},@{n="Location Description";e={$_."ExtensionAttribute2"}},@{n="Work Location";e={$_."City"}},@{n="Cube Location";e={$_."Office"}},@{n="Department Number";e={$_."EmployeeNumber"}},@{n="Space Cost Center Depth 0";e={$_."EmployeeNumber"}},@{n="Space Cost Center Depth 1";e={$_."Department"}},@{n="Space Cost Center Depth 3";e={(Get-ADUser -Identity $_.Manager -properties DisplayName).DisplayName}} | export-csv c:\results\contractors.csv -notype

 

is there a way to combine them...just have the first command also include that OU?


Viewing all articles
Browse latest Browse all 6937

Trending Articles