3

I have a few powershell Scripts (simple ones) I want to execute within Visual Studio Code.

When I run it with F5 the VSC turns orange (Debug Mode) for a few seconds and then turns back to normal without showing me anything.

This is the console output:

PS C:\Users\Huberdo\Documents\WindowsPowerShell> c:\Users\Huberdo\Documents\Meine Projekte\HD-Powershell-Scripts\Mailbox\HD-Mailbox.ps1

PS C:\Users\Huberdo\Documents\Meine Projekte\HD-Powershell-Scripts\Mailbox>

The Script should ask me to make a choice with Write-Host but it doesn't. Here is the main script:

function Show-Menu() {

Write-Host "================ $Title ================"

Write-Host "1: Press '1' for this option."
Write-Host "2: Press '2' for this option."
Write-Host "3: Press '3' for this option."
Write-Host "Q: Press 'Q' to quit."


do {
    Show-Menu
    $input = Read-Host "Please make a selection"
    switch ($input) {
        '1' {
            cls
            'You chose option #1'
        } '2' {
            cls
            'You chose option #2'
        } '3' {
            cls
            'You chose option #3'
        } 'q' {
            return
        }
    }
    pause
}
    until ($input -eq 'q')
}

I have installed and activated the Powershell Extension. I googled and searched here on Stackoverflow for possible solutions or similiar questions, but couldn't find any.

Am I doing something wrong? I tried it with x86 and x64 PS.

1 Answer 1

1

You are missing a closing bracket in the Show-Menu function.

function Show-Menu() {

Write-Host "================ $Title ================"

Write-Host "1: Press '1' for this option."
Write-Host "2: Press '2' for this option."
Write-Host "3: Press '3' for this option."
Write-Host "Q: Press 'Q' to quit."
}

do {
    Show-Menu
    $input = Read-Host "Please make a selection"
    switch ($input) {
        '1' {
            cls
            'You chose option #1'
        } '2' {
            cls
            'You chose option #2'
        } '3' {
            cls
            'You chose option #3'
        } 'q' {
            return
        }
    }
    pause
}
    until ($input -eq 'q')

If that does not solve your issue - then I would look into verifying that you installed the powershell extension properly and when you create the powershell script in VS you are choosing:

File -> New Project -> Powershell -> Powershell Script Project

Sign up to request clarification or add additional context in comments.

7 Comments

That'is the, as is the code is just calling ShowMenu in Show-Menu function, it can't stop looping when you call Show-Menu.
Hi thanks for the answer. I fixed your suggestions and have tried the same things in the preinstalled ISE and everyone worked over there. With Visual Studio Code it's not working. Also I have no "File -> New Project" menu. I have Visual Studio Code and not Visual Studio.
@GeraltDieSocke Ahh, okay. Sorry didn't catch you had visual studio code. So I can't attest to that, as I have Visual Studio 2013. Hmm, I would try the code I posted above. I can run that from Visual Studio and I get prompted for the input value. In your original code you have everything wrapped in the function so the function never gets called. Which is why the script might run and just exit.
@GeraltDieSocke Hmm, have you tried to reload the Powershell extension in the VSCode menu?(Screenshot #2 here: mikefrobbins.com/2017/08/24/… )
@GeraltDieSocke, once corrected I run the code in Visual studio code (1.19.3) and it works (PowerShell language support 1.5.1).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.