Hello Brett,
Regarding your post, I would like to clarify some more points:
- The expected loop should be happening to return to the wrtite-host part or the selection options?
- if you need to return to selection options, you could refer to the sample below.
param( [Parameter(Mandatory, Position = 1)] [string]$UserEmail )
cls
Write-Host " "
Write-Host "===============================================================" -Foreground Red
Write-Host " First connect to Exchange, then after every choice press the " -Foreground Red
Write-Host " the UP arrow to run the script again and you do NOT need to " -Foreground Red
Write-Host " reconnect to Exchange again as your session is still active. " -Foreground Red
Write-Host "===============================================================" -Foreground Red
$Title = "Email Archive Menu for $UserEmail"
$Info = " "
Write-Host " "
$options = [System.Management.Automation.Host.ChoiceDescription[]] @(
"&Connect to Exchange",
"&Mailbox Size",
"&Is Archiving Enabled?",
"&Enable Archiving ",
"Enable &Auto Expanding Archive ",
"&Start Archiving Task ",
"&Quit")
$a=0
while($opt -ne 6)
{
[int]$defaultchoice = 6
$opt = $host.UI.PromptForChoice($Title , $Info , $Options, $defaultchoice)
switch($opt)
{
0 {Invoke-Expression "Connect-ExchangeOnline" }
1 {Invoke-Expression "Get-Mailbox -Identity $UserEmail | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize"}
2 {Invoke-Expression "Get-Mailbox -Identity $UserEmail | Select ArchiveStatus, RetentionPolicy, AutoExpandingArchiveEnabled, ArchiveName"}
3 {Invoke-Expression "Enable-Mailbox -Identity $UserEmail -Archive" }
4 {Invoke-Expression "Enable-Mailbox -Identity $UserEmail -AutoExpandingArchive"}
5 {Invoke-Expression "Start-ManagedFolderAssistant -Identity $UserEmail"}
}
}
$opt=0
- if this is not what exactly you want, you are welcome to raise your idea in the post and I would check and reply.
Best Regards,
Ian Xue
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.