locked
The powercli code should message output as Invalid Options. RRS feed

  • Question

  • Hi everyone, I, along the help of the members of this forum have written this code. 

    I want that, if anyone gives invalid input, then the code should Message as "Invalid Input". 

    Now its only Giving again the Options to choose. 

    Thanks to Everyone in Advance. 

    Here is the code. 

    Function Menu{

    $xit = $false

    do{

    Write-host "1. Create Snapshot"

    Write-host "2. Revert Snapshot"

    Write-host "3. Delete Snapshot"

    Write-host "4. Quit and exit"

                    Switch( read-host "Please enter an option 1 to 4..." ){

                                    1 {listdbvms}

                                    2 {'two'}

                                    3 {'three'}

                                    4 {$xit = $true}

                    }

    } until($xit)

    }

    Menu

    Sunday, February 11, 2018 11:40 AM

All replies

  • You are asking for use to write you code for you.  You are not asking a question about scripting.  You need to learn basic PowerShell before posting in this forum.  We can't write your code for you and we cannot teach you how to write code.  That is your responsibility.

    Please carefully review the following links to set your expectation of technical forums.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests


    \_(ツ)_/

    Sunday, February 11, 2018 11:48 AM
  • Thanks for your words Moderator. 

    As i tried a code and it has worked, here is the code. 

    Function Menu{
    $xit = $false
    do{
    write-host ""
    write-host "1. List Snapshots"
    Write-host "2. Create A Snapshot"
    Write-host "3. Revert A Snapshot"
    Write-host "4. Delete A Snapshot"
    Write-host "5. Quit and exit"
    Write-Host ""

    Switch( read-host "Please enter an option 1 to 4..." ){

        1 {Listsnap}  #list snapshot
    2 {listdbvms} # create snapshot
    3 {listdbvmsandrevertsnap} # revert snapshot
    4 {Deletesnapshot}  # delete snapshot 
    5 {$xit = $true}  # exit
    default {
    Write-host "Invalid input. Please enter only '1' or '2' or '3' or '4' or '5 To Exit'" -ForegroundColor Yellow
    }
    }
    } until($xit)
    }

    Menu


    Sunday, February 11, 2018 1:09 PM
  • Hi,

    Good to hear that you have solved this issue by yourself. In addition, thanks for sharing your solution in the forum as it would be helpful to anyone who encounters similar issues.

    If there is anything else we can do for you, please feel free to post in the forum.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, February 12, 2018 5:16 AM