# Target list with Get-Content

**URL:** <https://forums.powershell.org/t/target-list-with-get-content/10028>\
**Category:** PowerShell Help\
**Created:** [January 25, 2018, 4:08pm UTC](https://forums.powershell.org/t/target-list-with-get-content/10028 "2018-01-25T16:08:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madams](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@madams](https://forums.powershell.org/u/madams)\
**Post date:** [January 25, 2018, 4:08pm UTC](https://forums.powershell.org/t/target-list-with-get-content/10028/1 "2018-01-25T16:08:38Z")

</div>

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

```
}

```

---

<div class="post-metadata">

**Author:** ![cristianrosu](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@cristianrosu](https://forums.powershell.org/u/cristianrosu)\
**Post date:** [January 26, 2018, 4:20am UTC](https://forums.powershell.org/t/target-list-with-get-content/10028/2 "2018-01-26T04:20:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/target-list-with-get-content/10028/3 "2024-05-16T20:37:14Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


