I need to extract a file containing all of my AD's. I am trying to do so with Get-ADuser. However, since the -Searchbase does not accept multiple sources,I did something like this:
'DC=AD1,DC=net','DC=1D2,DC=net','DC=AD3,DC=net','DC=AD4,DC=net' | foreach-object{ get-aduser -SearchBase $_ -Filter { ( Enabled -eq $True ) -and ( (sn -ne 'Empty') -or (givenName -ne 'empty')) -and ( (telephoneNumber -ne 'empty') -or (mobile -ne 'empty'))} -Properties * |Select sn,givenName,title,department,company,telephoneNumber,mobile,mail,employeeType,physicalDeliveryOfficeName,extensionAttribute15 | Export-CSV "c:\temp\Liste_collaborateurs.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation } But when I run it, I get this error 3 times :
get-aduser : The supplied distinguishedName must belong to one of the following partition(s): 'DC=bva,DC=net , CN=Configuration,DC=bva,DC=net , CN=Schema,CN=Configuration,DC=bva,DC=net , DC=DomainDnsZones,DC=bva,DC=net , DC=ForestDnsZones,DC=bva,DC=net'. At C:\Users\adm.wfd\Desktop\getaduser.ps1:3 char:1 + get-aduser -SearchBase $_ -Filter { ( Enabled -eq $True ) -and ( (sn -ne 'Empty' ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Comm ands.GetADUser
I guess the 3 times are for each AD my server isn't connected to. I can't run my command on each DC...
How can I get my csv with all my users on a single server ?
Thanks for your replies
71 Answer
Are you sure you are using the right domain controllers? Or the spelling and order fits? I tested your script in my own environment with multiple domain controllers and it worked. Your error message only appeared if I entered the wrong information.
Does the command work with the individual domain controllers when not executed in the loop?
What if you started your script directly on the domain controller?
I didn't test it myself.
Like that.
$Servers = 'server1','server2' ForEach ($Server in $Servers) { Invoke-Command -ComputerName $Server -ScriptBlock { get-aduser -Filter { ( Enabled -eq $True ) -and ( (sn -ne 'Empty') -or (givenName -ne 'empty')) -and ( (telephoneNumber -ne 'empty') -or (mobile -ne 'empty'))} -Properties * |Select sn,givenName,title,department,company,telephoneNumber,mobile,mail,employeeType,physicalDeliveryOfficeName,extensionAttribute15 | Export-CSV "c:\temp\Liste_collaborateurs.csv" -Encoding UTF8 -Delimiter ";" -NoTypeInformation } } 3