white helix white helix - 2 months ago 7x
PowerShell Question

Simple powershell list for changing IP-adresses

im a complete powershell newbie. I wanted to write a script that lets me change my static IP adresses for a specific network adapter. Changing the adress works perfect with the NetIPAdress cmdlets. The only thing I want to add is something like a list to choose wich adress I want to use. So like press 1 for adress scheme 1, press 2 for adress scheme 2 and so on.

I had a list like that in a batch script I wrote some time ago. There the code looked like this:

echo ================

echo IP Konfiguration

echo 1 = Speedport (feste IP .2.1)
echo 2 = Fritz!Box (feste IP .178.1)
echo 3 = Lancom (feste IP .1.100)
echo 4 = Agfeo (feste IP .100.1)

echo 0 = Abbrechen

set /P wahl=Auswahl:
if /i "%wahl%"=="1" goto:Speedport
if /i "%wahl%"=="2" goto:Fritz
if /i "%wahl%"=="3" goto:Lancom
if /i "%wahl%"=="4" goto:Agfeo
if /i "%wahl%"=="0" goto:exit

Thats what I want with powershell. Whats the easiest way to achieve that?


This question is bordering on being too broad for this site.. but there is a really easy way to do this in PowerShell 3+ using the Out-GridView cmdlet:

$ipChoices = @(
    '' ,
    '' ,
    '' ,

$ip = $ipChoices | Out-GridView -OutputMode Single

The list of IPs will come up in a Window, and it will allow you to choose one. That one will be returned to the pipeline (in this case, it will be assigned to the $ip variable).