如何在ps1运行后返回CMD提示恢复批处理文件

时间:2017-01-06 22:34:28

标签: powershell batch-file cmd

从CMD批处理文件调用powershell命令,但CMD仍处于PowerShell模式。如何退出PowerShell模式(在命令提示符下)并继续批处理文件? 当我运行当前批处理文件时,我必须键入exit以退出powershell会话。然后批处理文件从中断处继续。

1 个答案:

答案 0 :(得分:1)

Simples。

Shell脚本

@echo off
setlocal
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -file <full path to PowerShell file>
echo PowerShell returned rc %ERRORLEVEL%.
endlocal

简单的PowerShell文件

Write-Host -Object 'Hello World';
exit (Get-Random -Minimum -10 -Maximum 0);