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

Categories

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


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

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...