Reconnaissance and Enumeration

A tester's script `Get-Content ips.txt | ForEach-Object { Test-Connection $ip -Count 1 }` errors because the target is empty. Which change fixes it?

Show the answer

Correct answerD. Replace $ip with $_, the current pipeline object

AWhy not this: Where-Object filters items by a condition and would not pass each address to the command.

BWhy not this: $1 is a Bash positional parameter; in PowerShell it is another undefined variable.

CWhy not this: -Quiet only changes the output to True or False and does not supply a target.

DWhy this is right: $_ is the automatic variable for the current pipeline object, so each address from the file becomes the target.

$ip is never assigned, so the target is null. Inside ForEach-Object, $_ holds the current line from the pipeline. A Bash-style $1 is also just an undefined PowerShell variable.