0

I'm currently extracting data from a text file and then attempting to perform an action for each entry in the text file. See code below.

$Employees = Get-Content C:\User\Documents\UserWorkstations.txt Foreach($name in $Employees) { ping $name } 

After running my script it does not extract data from the text file and I get the following output:

cmdlet ForEach-Object at command pipeline position 2 Supply values for the following parameters: Process[0]: 
3
  • ... this is probably not a very good title Commented Jul 1, 2013 at 19:57
  • How's this Christian? Commented Jul 1, 2013 at 20:01
  • 3
    Try to be more specific and post an example coherent example. Your example uses a foreach statement loop while the error shows that the foreach-object was used. Commented Jul 1, 2013 at 20:14

1 Answer 1

1
Get-Content -Path 'C:\User\Documents\UserWorkstations.txt' | Foreach-Object { Write-Host ('Pinging {0}' -f $_) ping $_ } 
Sign up to request clarification or add additional context in comments.

1 Comment

This would be my route, I prefer to pipe into the foreach, and PowerShell seems to agree... Although as I recall | ` <newline> foreach... also works better still.