gpt4 book ai didi

sharepoint - 使用 PSTool 在远程机器上运行 PowerShell 脚本

转载 作者:行者123 更新时间:2023-12-02 23:31:46 25 4
gpt4 key购买 nike

我需要在远程机器上运行一个 PS 脚本,就像下面的代码一样。

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。脚本只有在 Powershell 的 64 位镜像中运行时才能正常运行。

当我尝试使用 PSTool 运行时,PSTool 总是最终从 %windir%\SysWoW64 文件夹调用 32 位 PowerShell,即使我明确提到了代码中显示的路径。

为什么会这样,我的问题有什么解决方案

问候,
天啊

最佳答案

当 32 位应用程序引用 c:\windows\System32 时,它会重定向到 SysWoW64

尝试使用 c:\windows\sysnative\windowspowershell\v1.0\powershell.exe

关于sharepoint - 使用 PSTool 在远程机器上运行 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5715049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com