title: Impersonation of user within PowerShell triggered from C# code
body: <p>I am using c# to invoke a powershell script, which has content inside it which should run as a specific user.</p>
  
  <ol>
  <li><p>I have C# implementation of impersonation completed logic mentioned as per with <a href="http://msdn.microsoft.com/en-us/library/ms998258.aspx#pagguidelines0001_impersonationdelegation" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms998258.aspx#pagguidelines0001_impersonationdelegation</a></p></li>
  <li><p>I have trouble with the implementation code which is the following:</p>
  
  <pre><code>PSInvocationSettings settings = new PSInvocationSettings();
  settings.FlowImpersonationPolicy = true;
  //settings.ErrorActionPreference = ActionPreference.Stop;
  IEnumerable input = null;
  resultsfromps = ps.Invoke&lt;PSObject&gt;(input, settings);
  </code></pre></li>
  </ol>
  
  <p>I did the lines for <code>PSInvocationSettings</code>, <code>flowimpersonationPolicy</code>, <code>ps.Invoke</code> using msdn help, but i'm not sure what I should set value to the <code>input</code> variable.</p>
  
  <p>So the code sorta works, it's creating a powershell invocation, but appears the script inside runs - but with empty username and empty password.</p>
  
  <p>ANy help on doing this appreciated !</p>