Create a powershell menu with an else if loop

I'm having trouble creating a powershell menu to deliver what i want.

The else if loop looks like this:
$computer = Read-host 'Identify the Computer by name or IP Address:"
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$regKey = $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system" )
If ($regKey.GetValue("undockwithoutlogon") -eq 1)
{
write-host "Enabled"
}
Else
{
write-host "Disabled"
}

Open in new window


basically it queries the value of said key and tells me whether its enabled or disabled. works as it should. However what i want to do is throw it in a menu such select option 1 for status. and the above code would be ran collecting the machine name and doing a query against the value and dumping whether its enabled or disabled.

below is my attempt

function Show-Menu
{
     param (
           [string]$Title = 'Undock without Logon'
     )
     cls
     Write-Host "================ $Title ================"
     
     Write-Host "1: Press '1' for Status."
     Write-Host "2: Press '2' to Enable enable undock."
     Write-Host "3: Press '3' to Disable undock."
     Write-Host "Q: Press 'Q' to quit."
}

do
{
     Show-Menu
     $input = Read-Host "Please make a selection"
     switch ($input)
     {
           '1' {
                cls
		$computer = Read-host 'Identify the Computer by name or IP Address:"
                $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
		$regKey = $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system" )
		If ($regKey.GetValue("undockwithoutlogon") -eq 1)
		{
		write-host "Enabled"
		}
		Else
		{
		write-host "Disabled"
		}
           } '2' {
                cls
                'You chose option #2'
           } '3' {
                cls
                'You chose option #3'
           } 'q' {
                return
           }
     }
     pause
}
until ($input -eq 'q')

Open in new window


when i run it the result i get is...

Identify the Computer by name or IP Address:"
                $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( LocalMachine, $computer)
                $regKey = $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system" )
                If ($regKey.GetValue("undockwithoutlogon") -eq 1)
                {
                write-host "Enabled"
                }
                Else
                {
                write-host "Disabled"
                }
           } 2 {
                cls
                You chose option:

Open in new window

LVL 1
ntr2defAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
The problem is on line 23.  For the Read-Host command you start with a single quote, but then end with a double quote, so neither of those is closed.  Just change one of them to match the other.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ntr2defAuthor Commented:
Haha wow, thanks for that i cant believe i overlooked that. thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.