Powershell Menu Display issue

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of AniyaNetworks AniyaNetworks 8 months ago.

  • Author
    Posts
  • #37428
    Profile photo of AniyaNetworks
    AniyaNetworks
    Participant

    Hello Friends,
    is there any way to change this script looks, i would like to see my in 1 column not like row.
    i tried to at "`n`r or only `n" but it is not working , please help.

    i would like to see them like this :

    Choose Action
    Grant/Remove permissions.
    [1] 1. Grant Send-As
    [2] 2. Grant FullAccess
    [3] 3. Grant Send-As & FullAccess
    [4] 4. Remove Send-As
    [5] 5. Remove FullAccess
    [6] 6. Remove Send-As and FullAccess
    [7] 7. Exit
    [?] Help (default is "7"):

    not like this way.
    Choose Action
    Grant/Remove permissions.
    [1] 1. Grant Send-As [2] 2. Grant FullAccess [3] 3. Grant Send-As & FullAccess [4] 4. Remove Send-As
    [5] 5. Remove FullAccess[6] 6. Remove Send-As and FullAccess [7] 7. Exit [?] Help (default is "7"):

    $Title = "Choose Action"
    $Message = "Grant/Remove permissions."

    $A = New-Object System.Management.Automation.Host.ChoiceDescription "&1. Grant Send-As" , `
    "Grant Send-As permissions."
    $B = New-Object System.Management.Automation.Host.ChoiceDescription "&2. Grant FullAccess" , `
    "Grant FullAccess permissions."
    $C = New-Object System.Management.Automation.Host.ChoiceDescription "&3. Grant Send-As & FullAccess" , `
    "Grant both Send-As & FullAccess permissions."
    $D = New-Object System.Management.Automation.Host.ChoiceDescription "&4. Remove Send-As" , `
    "Remove Send-As permissions."
    $E = New-Object System.Management.Automation.Host.ChoiceDescription "&5. Remove FullAccess" , `
    "Remove FullAccess permissions."
    $F = New-Object System.Management.Automation.Host.ChoiceDescription "&6. Remove Send-As and FullAccess" , `
    "Remove both Send-As & FullAccess permissions."
    $G = New-Object System.Management.Automation.Host.ChoiceDescription "&7. Exit" , `
    "Exit script"

    $Options = [System.Management.Automation.Host.ChoiceDescription[]]($A,$B,$C,$D,$E,$F,$G)
    $Result = $Host.UI.PromptForChoice($Title,$Message,$Options, 6)

    switch ($Result)

    {
    0 {"You selected Yes."}
    1 {"You selected No."}
    2 {"You selected Maybe."}
    }

  • #37431
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    Something like this?

    do {
        [int]$userMenuChoice = 0
        while ( $userMenuChoice -lt 1 -or $userMenuChoice -gt 7) {
            Write-Host -Object '1. Grant Send-As permissions.'
            Write-Host -Object '2. Grant FullAccess permissions.'
            Write-Host -Object '3. Grant both Send-As & FullAccess permissions.'
            Write-Host -Object '4. Remove Send-As permissions.'
            Write-Host -Object '5. Remove FullAccess permissions.'
            Write-Host -Object '6. Remove both Send-As & FullAccess permissions.'
            Write-Host -Object '7. Exit'
    
            [int]$userMenuChoice = Read-Host -Prompt 'Please choose an option'
    
            switch ($userMenuChoice) {
                1 {Do-Something1}
                2 {Do-Something2}
                3 {Do-Something3}
                4 {Do-Something4}
                5 {Do-Something5}
                6 {Do-Something6}
                default {Write-Warning -Message 'Nothing selected'}
            }
        }
    } while ( $userMenuChoice -ne 7 )
    
  • #37437
    Profile photo of AniyaNetworks
    AniyaNetworks
    Participant

    You are correct.
    but i would like to use my existing script. i just want to break the row's to the column.
    and i would like to user this the Default option as well, so when ever any body hit the enter it will run may be option 1 or 2.
    Please advise.

You must be logged in to reply to this topic.