Reputation: 5
I'm trying creating a powershell script to ping a range of IP by enter the first and last octet. If Write-host
is used the rest of the script won't execute. If write output is used the ..
doesn't work as a sequence
$StartIP = Read-Host -Prompt 'Input Start IP'
$EndIP = Read-Host -Prompt 'Input End IP'
Write-output $StartIP..$EndIP | % {"192.168.128.$($_): $(Test-Connection -count 1 -comp 192.168.128.$($_) -quiet)"}
Upvotes: 0
Views: 255
Reputation: 7340
You need to enclose it in parentheses:
Write-output ($StartIP..$EndIP) | % {"192.168.128.$($_): $(Test-Connection -count 1 -comp 192.168.128.$($_) -quiet)"}
If you omit Write-Output you can simple use:
$StartIP..$EndIP | % {"192.168.1.$($_): $(Test-Connection -count 1 -comp 192.168.1.$($_) -quiet)"}
Upvotes: 2