As a part of a system monitoring script I am unable to correctly identify the domains of a list of servers. Right now the segment looks like this:
$Serverlistfile = "C:\complist.txt" $Serverlist = Get-Content $serverlistfile foreach($computer in $serverlist) {get-ADDomainController -Discover | Select domain | Out-File -Append 'C:\domainlist.txt'}
When I run this it only posts one domain, I know a few of the servers in the $serverlistfile are on another domain. I have been able to run foreach commands in the past without issue. However, this command and another, that subs out Get-ADDomainController for Get-Content env:computername, are both reporting from the local machine and not from each listed in 'complist.txt'.
I am running this script from a Windows 7 box with administrator PowerShell ISE.