Powershell v3.0 pipe issue

PowershellActive DirectoryPowershell 3.0

Powershell Problem Overview


I'm having trouble with this command:

gc .\domains.txt | Get-ADDomain

As the name implies, domains.txt contains a list of Active Directory to query (all domains are in the same forest).

If I run it on my Windows 8 machine everything works fine and I get the expected results, instead on a Windows 2008 R2 SP1 member server (not a DC) with WMF 3.0 I get result only from the first domain in the list and for the others:

Get-ADDomain : A referral was returned from the server

If I query a domain in the list with:

Get-ADDomain <Domain name here>

it works fine.

My Workstation

Microsoft Windows 8 Enterprise (6.2.9200) x64

PS D:\Tools\Powershell> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.18010
BuildVersion                   6.2.9200.16384
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2

Server

Microsoft Windows Server 2008 R2 Standard SP1 (6.1.7601) x64

PS C:\Tools\Powershell> $PSVersionTable

Name                           Value
----                           -----
WSManStackVersion              3.0
PSCompatibleVersions           {1.0, 2.0, 3.0}
SerializationVersion           1.1.0.1
BuildVersion                   6.2.9200.16398
PSVersion                      3.0
CLRVersion                     4.0.30319.269
PSRemotingProtocolVersion      2.2

Update

If i run on the server:

gc .\domains.txt | %{ Get-ADDomain $_ }

it runs fine

TRACE

trace-command -Name ParameterBinding { "DOMAIN_1","DOMAIN_2" | Get-ADDomain } -PSHost

Server: http://pastebin.com/sRVJHaCU

Workstation: http://pastebin.com/kj3JV6nV

Thanks in advance

Powershell Solutions


Solution 1 - Powershell

I found an article that may help.

http://technet.microsoft.com/en-us/library/ee617224.aspx

From the look of your script you are providing the server using the text file. Is it possible the problem is the Windows 2008 server you are running the PowerShell script on is not in the same domain or the user you are logged in as does not have access to the domains where the other servers are members?

snippet from the above article:

> -If the Server parameter is specified and the Credential parameter is not specified: > --The domain is set to the domain of the specified server and the cmdlet checks to make sure that the server is in the domain of the > LocalComputer or LoggedOnUser. Then the credentials of the current > logged on user are used to get the domain. An error is returned when > the server is not in the domain of the LocalComputer or LoggedOnUser.

You might try adding the additional parameters for the Get-ADDomain commandlet such as -Identity, -AuthType, and -Credential

> Get-ADDomain [-Identity] [-AuthType { | > }] [-Credential ] [-Server ] > []

Solution 2 - Powershell

https://stackoverflow.com/questions/13192447/powershell-v3-0-pipe-issue

I just tried to run the cmdlet 'gc .\text.txt | Get-ADDomain' from a virtual Server 2008 R2 box that I have. I built a text file in the following format:

 Domain1
 Domain2
 Domain3

One thing to be sure of is that each domain is on it's own line in the text file. I can understand why the one syntax worked when you piped the STDOUT to:

%{ Get-ADDomain $_} 

because you are looping through all the information contained in the text file and only have the cmdlet work on a single value at a time. Unfortunately I don't have the RSAT package on my Win 8 desktop, so I can't test from my desktop. Hopefully this helps a little bit.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEsOsOView Question on Stackoverflow
Solution 1 - PowershellMunkeyWrenchView Answer on Stackoverflow
Solution 2 - PowershellDion PezzimentiView Answer on Stackoverflow