|
-
September 11th, 2016, 08:38 AM
#5
Re: Run Powershell commands inside Winform C# with another users crfedential
Hello
I tried this on my local laptop, it works:
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();
to connect to a remote machine you need to specify the machine to the WSManConnectionInfo
also make sure you enable PowerShell remoting : http://www.howtogeek.com/117192/how-...ote-computers/
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|