pshost

how to establish and enter a remote session using runspace in powershell

隐身守侯 提交于 2019-12-07 22:58:32
问题 I am trying to establish a session with a remote host B from my machine A, within a C# code. I am using runspace API for that. the code snippet is provided below Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); //constructing the vmname parameter here vmname = useralias + DateTime.Now.ToString(); Pipeline pipeline = runspace.CreatePipeline(); string scripttext = "$secpasswd = ConvertTo-SecureString '222_bbbb' -AsPlainText –Force"; string scripttext1 = "$mycreds = New