none
Accept users input in switch for list of templates RRS feed

  • Question

  • Hi Everyone,

    I want to accept users input for the list of templates available in vmware server, so that i can then create a vm from that template. 

    here is the code that i have written.  Thanks in Advance to everyone. 

    ########################### 
    Connect-VIServer -Server 10.209.130.40
    $template = Get-Template  # list of all vm templates available
    Write-Host

    $len = $template.length ## number of templates available. 

    Write-Host Available Templates

    for($i=0; $i -le $len - 1; $i++){Write-Host; Write-Host $i  $template[$i]}  ## showing user the list of templates they can use

    ##i am facing problem in below function. i want all above templates, to show to users, then users gives one number and then with New-VM command i can create the vm with that template. 

    function Get-Site
    {
    $site=Read-Host "Choose a site code"
    Switch ($site)
    {
    '1' {Write-Host You input server $Chosensite;}
    }
        return $Chosensite
    }
    & Get-Site
    • Moved by Bill_Stewart Friday, January 26, 2018 3:23 PM Unanswerable drive-by question
    Monday, December 11, 2017 2:35 PM

All replies

  • Hi Everyone,

    I want to accept users input for the list of templates available in vmware server, so that i can then create a vm from that template. 

    here is the code that i have written.  Thanks in Advance to everyone. 

    ########################### 

    Connect-VIServer -Server 10.209.130.40
    $template = Get-Template  # list of all vm templates available
    Write-Host

    $len = $template.length ## number of templates available. 

    Write-Host Available Templates

    for($i=0; $i -le $len - 1; $i++){Write-Host; Write-Host $i  $template[$i]}  ## showing user the list of templates they can use

    ##i am facing problem in below function. i want all above templates, to show to users, then users gives one number and then with New-VM command i can create the vm with that template. 

    function Get-Site
    {
    $site=Read-Host "Choose a site code"
    Switch ($site)
    {
    '1' {Write-Host You input server $Chosensite;}
    }
        return $Chosensite
    }
    & Get-Site


    • Merged by jrv Monday, December 11, 2017 2:45 PM DUPLICATE
    Monday, December 11, 2017 1:36 PM
  • We do not call functions like this "& Get-Site"

    only the function name is required.

    Get-Site

    Start here: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276


    \_(ツ)_/

    Monday, December 11, 2017 2:47 PM