Target list with Get-Content

Welcome Forums General PowerShell Q&A Target list with Get-Content

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
9 months, 3 weeks ago.

  • Author
    Posts
  • #92207

    Participant
    Points: 31
    Rank: Member

    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

    }

  • #92215

    Participant
    Points: 0
    Rank: Member

    Hi Matt, what's the output of $targets using Get-Content "\\ServerShare\ServerList.txt" after you run the script? What I suspect is the script cannot access the path \\ServerShare\ServerList.txt

The topic ‘Target list with Get-Content’ is closed to new replies.