Work with WebSockets in PowerShell
WebSocket is a small PowerShell module that helps you work with WebSockets.
It has a single command: Get-WebSocket.
Because Get
is the default verb in PowerShell, you can just call it WebSocket
.
You can use the WebSocket module within a container:
docker pull ghcr.io/powershellweb/websocket
docker run -it ghcr.io/powershellweb/websocket
Install-Module WebSocket -Scope CurrentUser -Force
Import-Module WebSocket -Force -PassThru
To connect to a websocket and start listening for results, use Get-WebSocket
# Because get is the default verb, we can just say `WebSocket`
# The `-Watch` parameter will continually watch for results
websocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch
To stop watching a websocket, simply stop the background job.
Import-Module .\
Get-Help Get-WebSocket |
%{ $_.Examples.Example.code} |
% -Begin { $exampleCount = 0 } -Process {
$exampleCount++
@(
"#### Get-WebSocket Example $exampleCount"
''
"~~~powershell"
$_
"~~~"
''
) -join [Environment]::Newline
}
}