# This looks good on paper but outputs incorrectly

**URL:** <https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207>\
**Category:** PowerShell Help\
**Created:** [November 10, 2020, 1:42pm UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207 "2020-11-10T13:42:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 10, 2020, 1:42pm UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/1 "2020-11-10T13:42:37Z")

</div>

I was trying to query for a few attributes of a User that exists in multiple domains and knew something was up when the same values cam back for i.e. UPN (which should be different)

What am I missing?

```
$Properties = @('Name','SamAccountName','UserPrincipalName','extensionAttribute10','extensionAttribute11')
$domains = (Get-ADForest).domains
$dcs = ForEach ($domain in $domains) {Get-ADDomainController -DomainName $domain -Discover -Service PrimaryDC | Select -ExpandProperty hostname}

ForEach ($dc in $dcs) {Get-ADUser MyUser -Properties $Properties | select $Properties }| FL
```

My variables are correctly enumerating.

Thanks

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [November 10, 2020, 7:28pm UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/2 "2020-11-10T19:28:02Z")

</div>

Not clear on the issue you are facing, are you getting any error ?  
You are just iterating for each $dcs but not telling Get-ADUser about the DC info using -Server parameter.

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 11, 2020, 7:33am UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/3 "2020-11-11T07:33:57Z")

</div>

Apologies for that. I get output but for each domain (count = 4) I get the same exact data from just 1. I want to query for the one User in each of the returned Domains (from each of the respective Domains’ DCs).

---

<div class="post-metadata">

**Author:** ![pattersongregory](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@pattersongregory](https://forums.powershell.org/u/pattersongregory)\
**Post date:** [November 11, 2020, 7:52am UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/4 "2020-11-11T07:52:45Z")

</div>

You just need to add the -Server parameter to Get-AdUser within your scriptblock on line 5. That Foreach construct runs the same command over and over with out the variable $dc in the scriptblock.

&nbsp;

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 11, 2020, 8:27am UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/5 "2020-11-11T08:27:21Z")

</div>

Thank guys, working now…(great to see your newest avatar, kvprasoon)

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [November 11, 2020, 7:21pm UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/6 "2020-11-11T19:21:05Z")

</div>

@jeff-taylor 🙂

Hope your issue got addressed.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/this-looks-good-on-paper-but-outputs-incorrectly/15207/7 "2024-05-16T20:28:22Z")

</div>


