Need data from different servers

I need data from 4 different servers, however, I am getting result only from the server I am running the script.

$domains = "us.jas.com","cm.jas.com","asia.jas.com","europe.jas.com"

foreach($domains in $domain){

Get-ADUser -filter * -Property EmployeeID, Givenname, sn,  EmailAddress, StreetAddress, City, State, Country, PostalCode |Select-object EmployeeID, Givenname, sn, EmailAddress, StreetAddress, City, State, Country, PostalCode |export-csv J:/eudcusersnew.csv
}

Also how can I put a filter that Employee id should not be a service account(employee id = "service") nor employee id should be like "234567a" or Givenname should not contain a '-"._
Aakash AggarwalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
add the append parameter...
|export-csv J:/eudcusersnew.csv -append

Open in new window

0
sirbountyCommented:
Also how can I put a filter that Employee id should not be a service account(employee id = "service") nor employee id should be like "234567a" or Givenname should not contain a '-"._

-filter {EmployeeID -like '234567a*' -and GivenName -notlike '*.*'}
0
Aakash AggarwalAuthor Commented:
Now getting error : A parameter cannot be found that matched parameter name Append.

$domains = "us.jas.com","cm.jas.com","asia.jas.com","europe.jas.com"

foreach($domain in $domains){

Get-ADUser -filter * -Property EmployeeID, Givenname, sn,  EmailAddress, StreetAddress, City, State, Country, PostalCode |Select-object EmployeeID, Givenname, sn, EmailAddress, StreetAddress, City, State, Country, PostalCode |export-csv J:/eudcusersnew1.csv -Append
}

Where should the below filter be put in this query ?

-filter {EmployeeID -like '234567a*' -and GivenName -notlike '*-*'} -> Here I need to filter for all EmployeeID that end with 'a' or where Employee ID = service and GivenName -notlike '*-*.
0
oBdACommented:
You're only getting results for the server you're running this on because you're not using the $domain loop variable anywhere.
Export-Csv's "-Append" is only available in PS 3.0 or later, which means you're still running PS 2.0 from 2009. WMF 5 still supports Windows 7; time to upgrade.
But even if -Append were available, you shouldn't use it that way. The file would have to be opened and closed for each and every user written, which slows things down immensely.
Use the ForEach-Object cmdlet instead of the ForEach statement, and just pipe the results to Export-Csv.
Assuming you have permissions in all domains, try this:
$domains = "us.jas.com", "cm.jas.com", "asia.jas.com", "europe.jas.com"
$domains | ForEach-Object {
	$domain = $_
	Write-Host "Processing $($domain) ..."
	Get-ADUser -Server $domain -Filter {(employeeID -ne 'Service') -and (employeeID -notlike '*234567a*') -and (givenName -notlike '*-*')} -Property EmployeeID, Givenname, sn,  EmailAddress, StreetAddress, City, State, Country, PostalCode |
		Select-Object -Property @{n='Domain'; e={$domain}}, EmployeeID, Givenname, sn, EmailAddress, StreetAddress, City, State, Country, PostalCode
} | Export-Csv -NoTypeInformation -Path J:\eudcusersnew.csv

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
Question answered.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.