Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run my Powershell Script inside of Visual Studio Code?

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.

like image 449
GeraltDieSocke Avatar asked Dec 18 '25 13:12

GeraltDieSocke


1 Answers

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

like image 197
Christopher Avatar answered Dec 20 '25 08:12

Christopher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!