Pipelining between two SEPARATE Powershell processes

让人想犯罪 __ 提交于 2019-12-01 23:06:55

I found this link that describes how to do what you're requesting: https://gbegerow.wordpress.com/2012/04/09/interprocess-communication-in-powershell/

I tested it and I was able to pass data between two separate Powershell sessions.

Server Side:

$pipe=new-object System.IO.Pipes.NamedPipeServerStream("\\.\pipe\Wulf");
'Created server side of "\\.\pipe\Wulf"'
$pipe.WaitForConnection(); 

$sr = new-object System.IO.StreamReader($pipe); 
while (($cmd= $sr.ReadLine()) -ne 'exit') 
{
 $cmd
}; 

$sr.Dispose();
$pipe.Dispose();

Client Side:

$pipe = new-object System.IO.Pipes.NamedPipeClientStream("\\.\pipe\Wulf");
 $pipe.Connect(); 

$sw = new-object System.IO.StreamWriter($pipe);
$sw.WriteLine("Go"); 
$sw.WriteLine("start abc 123"); 
$sw.WriteLine('exit'); 

$sw.Dispose(); 
$pipe.Dispose();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!