Welcome to OGeek Q&A 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

question from:https://stackoverflow.com/questions/65599163/sending-commands-to-existing-powershell-with-streamdeck-buttons

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...