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