Hi All,
I am currently using this script to export a list of AD users from a CSV file input. The process is running correctly, but it generates several errors. This is because I believe it queries all the domains returning an error when it doesn’t find the object in the domain.
$csvdata = Import-Csv -Path $csvfile$result = foreach ($domain in $domains)
{
$csvdata | ForEach-Object { Get-ADUser -Server $domain -Identity $_.muid } | select-object -property DistinguishedName
}
$result | Out-file -Append -FilePath $txtfile1
Get-ADUser : Cannot find an object with identity: 'XXXXXXXX' under: 'DC=corp,DC=domain,DC=com'. At line:3 char:33 + ... ForEach-Object { Get-ADUser -Server $domain -Identity $_.muid } | sel ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (XXXXXXXX:ADUser) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUserI understand if I use the cmdlet filter something like -eq it would then return no errors, but I am unable to make it work so far.
Is there any way you can help me with the script above to filter only the users found and return no errors?
Thanks,
PowerDude