Author Posts

May 23, 2018 at 10:51 am

Hi,
I have a script that configures an ESXi server for the first time, and I need to add an option to configure the connection to a storage.
I'm facing problems to create a menu from a list of some vmnics that the user must choose two to connect to the storage.
What I need:

First I get all vmnics that are 10 Gigabit and are Up:

Get-VMHostNetworkAdapter | Where {($_.ExtensionData.Spec.LinkSpeed.SpeedMb -ge 10000) -and ($_.BitRatePerSec -ne 0)} | Select DeviceName -ExpandProperty DeviceName

Then I need to ask the user to choose two of those vmnics to configure the connection to the storage.
How can I make so the user can choose two vmnics from that list so I can use that answers to continue the rest of the script?

May 23, 2018 at 4:21 pm

This isn't "exact" code, just trying to give you an idea on the logic.

# Get the adapters
$adapters = Get-VMHostNetworkAdapter | Where {($_.ExtensionData.Spec.LinkSpeed.SpeedMb -ge 10000) -and ($_.BitRatePerSec -ne 0)} | Select -ExpandProperty DeviceName

# Display a menu
$adaptercount = $adapters.count
for ($I = 1; $I -lt $adaptercount; $i++) {
 Write-Host "$I - $($adapters[$I])"
}

# prompt
$choice = Read-Host "Which One?"

# $adapters[$choice] will be the one picked

The way you've written your first command this'll give you the device name of the selected one.

May 23, 2018 at 4:24 pm

Don Jones,

Great! That is what I was looking for, an idea on the logic!

Really thank you!