我有一些要在 Visual Studio Code 中执行的 powershell 脚本(简单脚本)。
当我使用 F5 运行它时,VSC 变成橙色( Debug模式)几秒钟,然后恢复正常,但没有显示任何东西。
这是控制台输出:
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>
脚本应该要求我使用 Write-Host
做出选择,但它没有。
这是主要脚本:
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')
}
我已经安装并激活了 Powershell 扩展。 我在 Stackoverflow 上用谷歌搜索并搜索了可能的解决方案或类似问题,但没有找到。
我做错了什么吗?我用 x86 和 x64 PS 试过了。
最佳答案
您在 Show-Menu 函数中缺少右括号。
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')
如果这不能解决您的问题 - 那么我会考虑验证您是否正确安装了 powershell 扩展,以及当您在 VS 中创建您选择的 powershell 脚本时:
文件 -> 新建项目 -> Powershell -> Powershell 脚本项目
关于powershell - 如何在 Visual Studio Code 中运行我的 Powershell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48746982/