As suggested in the comment information, the IP Address in the ip.txt
is probably preceded and/or succeeded by one or more new line (Cr/Lf) characters.
If you use the -Raw
parameter, Get-content
will return all the lines including newline characters as a single string ([String
]). At the other hand, if you do not include the -Raw
, Get-content
will return all the lines as separate strings ([String[]]
), which might cause an issue in your case as well.
To remove all possible white-space characters arround the IP Address, you might use the Trim()
method which removes all leading and trailing white-space characters from the current string by default:
$myip=Get-content 'C:\Users\USER\Documents\ip.txt' -Raw
$myip = $myip.trim()
netsh interface portproxy add v4tov4 listenport=3390 listenaddress=0.0.0.0 connectport=3390 connectaddress=$myip
CLICK HERE to find out more related problems solutions.