Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

sending commands to existing powershell ( with streamdeck buttons)

I have question on how to "reuse" a running powershell: Situation: I have a Streamdeck where I can fire up Powershell commands with different buttons. I managed to get a powershell script (which was a hustle itself with my lack of coding knowledge) that opens up a connection to another PC (IP/Port). Keeping the shell open, I can type commands to be executed on the remote PC. When I put those commands in a script to be fired up by a different streamdeck-button, the streamdeck opens up another shell trying to send the command. Problem: the new shell doesn t know the existing tcp-connection .. so...no command comes through. How can I either tell the new shell to use the existing connection or how can I make the connection "globally" accessible by different powershells?

This does the connection:

$RemotePC = "xxx.xxx.xxx.xxx"
$CPort = "yy"
$tcpConnection = New-Object System.Net.Sockets.TcpClient ($RemotePC , $CPort)
$tcpStream = $tcpConnection.GetStream()
$writer = New-Object System.IO.StreamWriter($tcpStream)
$writer.AutoFlush = $true

Hope my problem is not too trivial...and yes, I googled a lot ;)

Thanx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...