使用 PSTool 在远程机器上运行 PowerShell 脚本 [英] Running PowerShell script on a remote machine using PSTool
问题描述
我需要在远程机器上运行一个 PS 脚本,就像下面的代码一样.
I need to run a PS script on a remote machine, am doing as in the below code.
Process psExecer = new Process
{
StartInfo =
{
UseShellExecute = false,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = @"c:\PsTools\PsExec.exe",
Arguments = @"c:\windows\System32\cmd.exe /k c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe E:\Scripts\SetUP.ps1 -u super -p Pass -s"
}
};
psExecer.Start();
psExecer.WaitForExit();
Thread.Sleep(5000);
问题是脚本有一些 sharepoint cmdlet,它必须加载 sharepoint PSSnapin.脚本仅在 64 位 Powershell 映像中运行时才能正常运行.
problem is that script has some sharepoint cmdlets and it has to load sharepoint PSSnapin. Script runs properly only when its run in 64 bit image of Powershell.
当我尝试使用 PSTool 运行时,PSTool 总是最终从 %windir%\SysWoW64 文件夹调用 32 位 PowerShell,即使我明确提到了代码中显示的路径.
When i tried to run using PSTool, PSTool always ends up invoking 32 bit PowerShell from %windir%\SysWoW64 folder, even when i explicitly mentioned the path as shown in the code.
为什么会这样,我的问题有什么解决办法
Why is it so, what is the solution to my problem
问候,哎呀
推荐答案
当 32 位应用程序引用 c:\windows\System32 时,它被重定向到 SysWoW64
When a 32-bit app references c:\windows\System32 it's redirected to SysWoW64
尝试使用 c:\windows\sysnative\windowspowershell\v1.0\powershell.exe
Try using c:\windows\sysnative\windowspowershell\v1.0\powershell.exe
这篇关于使用 PSTool 在远程机器上运行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!