Having trouble figuring out why my foreach works with literal values and not with get-content. When I uncomment the get-content line and then comment the second $targets line, the foreach statement correctly loads the target list, but doesn’t execute the function, which is starting a scheduled task on the remote server.
However, if I give a literal targets list like the example below, works just fine. Any thoughts?
#$targets = Get-Content “\ServerShare\ServerList.txt”
$targets = “Server1”,“Server2”
foreach ($target in $targets)
{
Invoke-Command -computername $target -ScriptBlock ${Function:Run-Function} -ArgumentList $target -jobname $target -AsJob
}