Forum Discussion
charlie4872
Sep 01, 2022Brass Contributor
Get Logon Server From List Of Computers
Hello I am trying to find the logon server $env:logonserver from a list of computers in a .txt file and have the results exported out to a .csv file for a domain migration project I am working on. I...
farismalaeb
Sep 02, 2022Iron Contributor
You dont need to use the variable before the foreach.
Use this.
$computers = get-content C:\MyFile.txt
foreach ($computer in $computers){
$results=invoke-command -computer $computer -scriptblock {$env:logonserver}
Add-Content C:\MyResult.txt -Value $results
}