Hi guys,
here I am (again!) and I need some help (again!!)
What I am trying to do:
- Get the list of IP address on localhost
- Use that list to build a menu where each IP address is a menu option
- When the user choose one option, get the selected IP address in a variable for further use.
Where am I:
$TestIP=Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DefaultIpGateway} | Select-Object -ExpandProperty IPAddress $arguments=@() $CountIP=$TestIP.Count $rootfolder=1..$CountIP $title="Website binding IP Address selection" $message="Please select an IP address for the website you're about to create." $arguments+=$Cancel=New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel", ` "Cancels and exits the script." $i=0 ForEach($IP in $TestIP) { $i++ $arguments+=New-Object System.Management.Automation.Host.ChoiceDescription "`&$i $IP", ` "Select $IP for the website to create." } $options=[System.Management.Automation.Host.ChoiceDescription[]]$arguments $result=$Host.UI.PromptForChoice($title, $message, $options, 0)
But that doesn't work... The menu is buit, but first I don't know why I get an extra (unwanted) $i in front of each IP address:
[C] Cancel [1] 1 xxx.xxx.xxx.xxx [2] 2 xxx.xxx.xxx.xxx [?] Help
And I can't figure out how to get the chosen IP address after the user has select it...