Create options so the user can choose

Welcome Forums General PowerShell Q&A Create options so the user can choose

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
9 months, 4 weeks ago.

  • Author
    Posts
  • #101038

    Participant
    Points: 45
    Rank: Member

    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?

  • #101052

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

    • #101056

      Participant
      Points: 45
      Rank: Member

      Don Jones,

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

      Really thank you!

The topic ‘Create options so the user can choose’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort