2

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);  

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

4
  • Just curious, but why do you load cmd then get that to load powershell, rather than running powershell directly? Commented Apr 19, 2011 at 10:35
  • Tried directly loading powershell gave same error, so tried loading using cmd which was not of much use Commented Apr 19, 2011 at 10:43
  • I'm assuming it's a typo, but you state you need to run the 64-bit version of powershell, but then load it from System32. Can you update your question to make sure there's no confusion...? Commented Apr 19, 2011 at 10:50
  • any full source code with final solution working ? Commented Sep 5, 2012 at 10:54

2 Answers 2

2

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Jako you are right, I was facing the issue because the PsTool is a 32 bit application and hence always 32 bit powershell was being called.Thanks a lot for the info.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.