首页 > 解决方案 > 我正在尝试从批处理文件批处理文件运行 powershell 脚本,但它似乎终止了批处理文件

问题描述

我有一个试图在批处理文件中调用的 PowerShell 脚本。Powershell 脚本会更新一些由后续 .exe 文件使用的凭据,这些凭据会在一小时后过期。然后我想终止 PowerShell 脚本,重新启动 PowerShell 脚本,然后重新启动 .exe。这是一个重现我的问题的简单示例:

测试.bat

::@echo off
title Started at %time%
pause
Call CallPSWrapper.bat
::Never hits this pause
pause
echo call the .exe here

CallPSWrapper.bat:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -ExecutionPolicy bypass -NoProfile -File .\MyPowerShell.ps1

我的PowerShell.ps1:

Write-Output "Waiting"
Start-Sleep -Seconds 30

我最初尝试从 test.bat 调用 MyPowerShell.ps1,但尝试将其更改为由中间批处理文件调用,希望 PowerShell 只会杀死 CallPSWrapper.bat。

标签: powershellbatch-filecmd

解决方案


推荐阅读