Forum Discussion

coxygt's avatar
coxygt
Brass Contributor
Jul 26, 2021

Interactive menu to choose task

Hi,

I have started a new script for a routine task (checking resource meeting settings).  The menu appears fine, but I am now not at all sure how to complete the script.

#Connect to Exchange Online
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
"$MFAExchangeModule"
$un = Read-Host "Enter Username"
Connect-EXOPSSession -UserPrincipalName $un
#Build a menu of choices
Do {
 if($Action -eq "")
 {
  if($Delay -eq $true)
  {
   Start-Sleep -Seconds 2
  }
  $Delay=$true
 Write-Host "********************** Resource Calendar Delegate Booking Settings *********************" -ForegroundColor Yellow
 Write-Host "*                                                                                      *" -foregroundcolor yellow
 Write-Host "*    1.Change delegate booking to Automatic                                            *" -foregroundcolor yellow
 Write-Host "*    2.Change delegate booking to Manual                                               *" -ForegroundColor Yellow
 Write-Host "*    3.Check another resource calendar                                                 *" -ForegroundColor Yellow
 Write-Host "*    4.Quit                                                                            *" -ForegroundColor Yellow
 Write-Host "*                                                                                      *" -foregroundcolor yellow
 Write-Host "****************************************************************************************" -ForegroundColor Yellow
 $i = Read-Host 'Please choose the action to continue' 
 }}
 while ($Action =""
 else
 {
  $i=$Action
 }
 
Basically, choosing Option 1 should result in 
Set-CalendarProcessing -Identity $roomname -AutomateProcessing AutoAccept -DeleteComments $true -AddOrganizerToSubject $true -AllowConflicts $false
Option 2 should result in 
Set-CalendarProcessing -Identity $roomname -AutomateProcessing None
Option 3 should simply start the script again from the point of displaying the menu
Option 4 should basically exit
 
Completely stuck, any help appreciated.
  • @nless you need the do/while loops I'd throw it away ... 

    $menu = @"
    ********************** Resource Calendar Delegate Booking Settings *********************
    *                                                                                      *
    *    1.Change delegate booking to Automatic                                            *
    *    2.Change delegate booking to Manual                                               *
    *    3.Check another resource calendar                                                 *
    *    4.Quit                                                                            *
    *                                                                                      *
    ****************************************************************************************
    "@
    Write-Host $menu -ForegroundColor Yellow
    
    $action = Read-Host 'Please choose the action to continue' 
    
    switch($action)
    {
        1 { # code goes here }
        2 { # code }
        3 { # code }
        default { exit # catch all }
    }
  • psophos's avatar
    psophos
    Brass Contributor

    coxygt  Use the switch statement.

    switch($action)
    {
        1 { # code goes here }
        2 { # code }
        default { # catch all }
    }
  • psophos's avatar
    psophos
    Brass Contributor

    @nless you need the do/while loops I'd throw it away ... 

    $menu = @"
    ********************** Resource Calendar Delegate Booking Settings *********************
    *                                                                                      *
    *    1.Change delegate booking to Automatic                                            *
    *    2.Change delegate booking to Manual                                               *
    *    3.Check another resource calendar                                                 *
    *    4.Quit                                                                            *
    *                                                                                      *
    ****************************************************************************************
    "@
    Write-Host $menu -ForegroundColor Yellow
    
    $action = Read-Host 'Please choose the action to continue' 
    
    switch($action)
    {
        1 { # code goes here }
        2 { # code }
        3 { # code }
        default { exit # catch all }
    }

Resources