title: Not able to call a function recursively in Powershell
body: <p>I am creating a menu driven Script for the users to perform certain actions based on the the options they choose. Just in case they select a wrong option, I am trying to display the choices again after displaying appropriate message. However, whenever any wrong choice is selected, and the function is being called from within itself, I am getting a ParseException instead. Can you please see if something is wrong here?</p>
  <pre><code>Class O_Manager {
        
                   [int]$val
  
                   ShowMenu() {                                                                                                                                           
                                  Write-Host &quot;    Please choose from below Options : &quot;                       
                                  Write-Host &quot;                                     &quot;                                           
                                  Write-Host &quot;       1. Option1 &quot;
                                  Write-Host &quot;       2. Option2 &quot;
                                  Write-Host &quot;       3. Option3 &quot;
  
                                  $this.val = Read-Host &quot;    Enter your Choice here &quot;
  
                                  switch($this.val)
                                  {
                                                  1 {&quot;ONE&quot;}
                                                  2 {&quot;TWO&quot;}
                                                  3 {&quot;THREE&quot;}
                                                  default {&quot;Incorrect choice selected&quot; 
                                                           ShowMenu()}
                                  }
  
  }
  }
  
  $obj = New-Object O_Manager
  $obj.ShowMenu()
  </code></pre>