首页 > 解决方案 > 在 32 位模式下运行 Powershell 脚本

问题描述

我目前尝试编写一个 PowerShell 脚本,我必须在其中导入一个 32 位模块。该脚本应由 Windows 任务计划程序自动启动。我编写了以下批处理文件,它启动了 powershell 脚本:

powershell.exe -ExecutionPolicy RemoteSigned -file "\myFilePath\myScript.ps1"
exit 0

我的问题是,ps 文件现在在 64 位版本中运行,因为我在 64 位环境中执行它。我可以将脚本“安全”为 64 位版本或类似的版本吗?

更新:

我已经试过了%windir%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPo[...]。这对我不起作用。在我的错误日志中,它写入脚本的典型错误是:

“‘New-RDBaseItem’一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。”

谢谢您的帮助!

标签: powershellscripting32bit-64bit

解决方案


尝试像这样运行它:

$script = Start-Job -ScriptBlock {
  powershell.exe -ExecutionPolicy RemoteSigned -file "\myFilePath\myScript.ps1"
} -RunAs32
$script | Wait-Job | Receive-Job

推荐阅读