Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Issues performing actions with foreach (actions only being performed on local machine)

$
0
0

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.


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>