首页 > 解决方案 > 如果在 exe 中转换,Powershell 进度条不显示

问题描述

如果我在控制台中执行脚本,进度条会完美显示,但如果我将脚本转换为 exe,ps2exe进度条不会显示。

我该如何解决这个问题?谢谢

$totalTimes = 10
$i = 0

for ($i=0;$i -lt $totalTimes; $i++) {
   $percentComplete = ($i / $totalTimes) * 100
   Write-Progress -Activity 'Doing thing' -Status "Did thing $i  times" -PercentComplete $percentComplete
   sleep 1
}

标签: powershell

解决方案


你试过PS2EXE-GUI吗?

它将 PowerShell 脚本“转换”为 EXE 文件,可选择作为 GUI 应用程序:

.\ps2exe.ps1 -noconsole -inputFile 'test.ps1' -outputFile 'test.exe' 

如果test.ps1包含您的示例代码,运行 .\test.exe将显示一个 GUI 进度条,如下所示:

在此处输入图像描述


推荐阅读