none
Menú modo texto RRS feed

  • Pregunta

  • Buenas a todos.

    He estado mirando ejemplos de como podría hacer un menú en PowerShell para que al escoger una opción haga una tarea determinada, pero los que encuentro no me funcionan o no son lo que busco exactamente.

    ¿Alguien tiene algo por ahí?

     

    Gracias.

    viernes, 12 de agosto de 2011 10:24

Respuestas

  • Bueno.

    Me respondo a mí mismo.

    He encontrado buscando y rebuscando en este enlace una posible solución a lo que estaba buscando.

    http://powershellcommunity.org/Forums/tabid/54/aft/4944/Default.aspx

    function menu1($script:selectNum)
    {
    cls
    write-host "WEBPAGE BUILDER MENU"
    write-host
    echo "2. View HTML code"
    echo "3. Publish Webpage"
    echo "4. Remove Webpage"
    echo "5. Exit"
    write-host
    $script:selectNum = read-host "Please Make a selection >> " 
    
    }
    
    function submenu
    {
    switch ($script:selectNum) {
    1 {"You have selected option 1"}
    2 {"You have selected option 2"}
    default {"Oops, what happened?..."}
    }
    }
    
    menu1
    submenu
    
    

    Edito:

    He encontrado otro ejemplo en otra URL el cual parece bastante interesante por si a alguien le pudiese interesar.

    http://www.blkmtn.org/powershell-a-simple-menu



    # ==============================================================================================
    #  NAME: get-VMspace.ps1
    # AUTHOR: Steven Peck
    #  DATE: 7/7/2008
    # COMMENT: Get LUN space from VMHosts attached to Virtual Centers
    #     Sort by LUN Name and -unique
    # ==============================================================================================
     
    # Set report output directory
    $outputDir = "C:\support\Output"
    # Set date format for use in file name
    $date = Get-Date -uformat "%y%m%d"
     
    # Explain what the script does
    Write-Host " " 
    Write-Host "This script will scan all attached storage on VMHost systems connected to a given Virtual Center server."
    Write-Host " " 
     
    # Select environment MENU
    Write-Host "Choose your environment."
    Write-Host "1. Production"
    Write-Host "2. Test"
    Write-Host "3. Development"
    Write-Host " "
    $a = Read-Host "Select 1-3: "
     
    Write-Host " "
     
    switch ($a) 
      { 
        1 {
          "** Production Environment **";
          Get-VIServer -server SERVER001 -protocol https -user speck;
          $environment = "Production";
          break;
         } 
        2 {
          "**Test environment **";
          Get-VIServer -server 10.10.10.125 -protocol https -user domain\speck;
          $environment = "test";
          break;
         } 
        3 {
          "** Development environment **";
          Get-VIServer -server 192.168.5.5 -protocol https -user domain\speck;
          $environment = "dev";
          break;
         } 
        default {
         "** The selection could not be determined **";
         break;
         }
      }
    
    $space = Get-VMHost | Get-Datastore
    
    $space | sort Name -unique | Select-Object Name, CapacityMB, FreeSpaceMB | Export-Csv $outputDir/$date.$environment.space.csv -NoType
     Write-Host "Reports are located in $outputDir."

    • Marcado como respuesta Alex Millà miércoles, 17 de agosto de 2011 20:51
    miércoles, 17 de agosto de 2011 20:51