I’m using the powershell script below to add multiple ip’s to a specific firewall rule in this case Rule SMB.
$name = Get-NetFirewallRule -DisplayName "Rule smb" $ips = @("192.168.1.150", "192.168.1.151") foreach ($r in $name) { Set-NetFirewallRule -DisplayName $r.DisplayName -RemoteAddress $ips }
In this case I need to edit the script every time I want to use this. So I thought I’ll change the following:
instead of using
$ips = @("192.168.1.150", "192.168.1.151")
I want to use something like this which I tried
$ips = @("Read-Host "Enter your server ip's")
When I run the script i will prompt me to enter the ip addresses I tried to enter 192.168.1.150,192.168.1.151 to add both addresses to the rule. But the script fails. I get a error that the address is invalid. Addresses may be specified as ip addresses, ranges etc…
Also tried to enter “192.168.1.150, " 192.168.1.151” with this the script will fail to.
the scripts works when I enter only a single ip address so when I want to enter multiple addresses the script fails.
Can anyone help me with a solution?
Thanks a lot!
JRB