WSManConnectionInfo connectionInfo = new WSManConnectionInfo(); connectionInfo.ComputerName = "ServerName"; System.Security.SecureString SecPass = new System.Security.SecureString(); string password = "xxx"; foreach (char c in password) { SecPass.AppendChar(c); } connectionInfo.Credential = new PSCredential(@"abcd", SecPass); Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo); runspace.Open(); using (PowerShell ps = PowerShell.Create()) { ps.Runspace = runspace; ps.AddScript("Get-Service"); // Do something with result ... PSCommand new1 = new PSCommand(); String machinename = "ServerName"; String file = "D:\\abc.txt"; //new1.AddCommand("Invoke-Command"); new1.AddParameter("computername", machinename); new1.AddParameter("filepath", file); ps.Commands = new1; Console.WriteLine(ps.Commands.ToString()); var results = ps.Invoke(); //Collection<psobject> results = ps.Invoke(); } runspace.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)