开发者

Running PowerShell script on a remote machine using PSTool

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 开发者_JAVA技巧Pass -s"        
                }
            };

            psExecer.Start();
            psExecer.WaitForExit();
            Thread.Sleep(5000);  

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.

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

Regards, Jeez


When a 32-bit app references c:\windows\System32 it's redirected to SysWoW64

Try using c:\windows\sysnative\windowspowershell\v1.0\powershell.exe


The problem you invoke is the side effect of the process virtualisation due to UAC.

Here are three solutions:

1. Remove UAC on the target computer

2. WinRM

If you want to remote execute PowerShell scripts on targets like Windows 2008 R2 and Windows Seven, the best way is to use WSMan just have a look to about_Remote help In PowerShell.

3. try to remove virtualisation on the process you invoke on the remote computer

To prevent virtualization, add a manifest in the same directory as the EXE file for which you want to remove virtualisation. A manifest is an XML file named yourexename.exe.manifest. You can find in this site a manifest sample. Try to set the requestedPrivileges to asInvoker.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜