powershell ExecutionPolicy 设置不正确

问题描述

我正在从批处理脚本运行 powershell。这是示例代码

   powershell.exe Set-ExecutionPolicy Bypass -Force
   set logDir=C:\testfolder\
   mkdir %logDir%
   powershell.exe C:\<folder>\test.ps1 >> "%logDir%test.log"

出现错误:“test.ps1”未被识别为 cmdlet 的名称 此问题仅发生在特定 VM 上。在其他 Windows 机器上完成相同的脚本执行。 需要解决此问题。

解决方法

每当我希望 powershell.exe 执行 ps1 文件时,我都会使用以下语法:

powershell.exe -f "C:\<folder>\test.ps1"

告诉 exe 执行文件而不是 Cmdlet。