title: WSManConnectionInfo and PSCredential for Runspace Powershell Commands as Another User
body: <p>I've been trying to figure out how to enable Runspace Powershell commands to run as another user and I've found examples such as <a href="http://forums.codeguru.com/showthread.php?556741-Run-Powershell-commands-inside-Winform-C-with-another-users-crfedential" rel="nofollow noreferrer">this</a>:</p>
  
  <pre><code>var con = new WSManConnectionInfo();
  con.Credential = new PSCredential("user", "pass".ToSecureString());
  Runspace runspace = RunspaceFactory.CreateRunspace(con);
  runspace.Open();
  Pipeline pipeline = runspace.CreatePipeline();
  pipeline.Commands.Add("dir");
  pipeline.Commands.Add("Out-String");
  var results = pipeline.Invoke();
  runspace.Close();
  </code></pre>
  
  <p>However this does not work, because <code>con.Credential</code> is a read only property. I don't know how this guy could claim it works.</p>
  
  <p>When I try doing it differently:</p>
  
  <pre><code>var cred = new PSCredential(objWINS + "\\" + objUser, objPW.ToSecureString());
  var con = new WSManConnectionInfo(cred);
  </code></pre>
  
  <p>The <code>WSManConnectionInfo</code> class wants more information such as a Uri and a Shell string. I'm just trying to run Powershell commands here, there's no Uri I need to connect to, I have no idea what the shell is for either and the only thing I can find in searches is this URL:</p>
  
  <p>"<a href="http://schemas.microsoft.com/powershell/Microsoft.PowerShell" rel="nofollow noreferrer">http://schemas.microsoft.com/powershell/Microsoft.PowerShell</a>"</p>
  
  <p>There is not a lot of info out there on this class, nothing that I can really glean any info on what to add as the Uri at least.</p>