{"id":22959195,"url":"https://github.com/powershellweb/websocket","last_synced_at":"2025-08-13T05:31:35.400Z","repository":{"id":265015254,"uuid":"894842859","full_name":"PowerShellWeb/WebSocket","owner":"PowerShellWeb","description":"Work with WebSockets in PowerShell","archived":false,"fork":false,"pushed_at":"2024-12-07T00:27:11.000Z","size":103,"stargazers_count":8,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-14T18:16:05.153Z","etag":null,"topics":["container","powershell","powershell-module","websocket","websocket-client"],"latest_commit_sha":null,"homepage":"https://websocket.powershellweb.com/","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PowerShellWeb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["StartAutomating"]}},"created_at":"2024-11-27T05:10:17.000Z","updated_at":"2024-12-12T07:50:10.000Z","dependencies_parsed_at":"2024-11-27T10:19:35.766Z","dependency_job_id":null,"html_url":"https://github.com/PowerShellWeb/WebSocket","commit_stats":null,"previous_names":["powershellweb/websocket"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerShellWeb%2FWebSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerShellWeb%2FWebSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerShellWeb%2FWebSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerShellWeb%2FWebSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PowerShellWeb","download_url":"https://codeload.github.com/PowerShellWeb/WebSocket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229737479,"owners_count":18116456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["container","powershell","powershell-module","websocket","websocket-client"],"created_at":"2024-12-14T18:16:14.847Z","updated_at":"2025-08-13T05:31:35.356Z","avatar_url":"https://github.com/PowerShellWeb.png","language":"PowerShell","funding_links":["https://github.com/sponsors/StartAutomating"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n    \u003cimg alt='WebSocket Logo (Animated)' style='width:33%' src='Assets/WebSocket-Animated.svg' /\u003e\n    \u003cbr /\u003e\n    \u003ca href='https://www.powershellgallery.com/packages/WebSocket/'\u003e\n        \u003cimg src='https://img.shields.io/powershellgallery/dt/WebSocket' /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n# WebSocket\n\nWork with WebSockets in PowerShell\n\nWebSocket is a small PowerShell module that helps you work with WebSockets.\n\nIt has a single command:  Get-WebSocket.\n\nBecause `Get` is the default verb in PowerShell, you can just call it `WebSocket`.\n\n## WebSocket Container\n\nYou can use the WebSocket module within a container:\n\n~~~powershell\ndocker pull ghcr.io/powershellweb/websocket\ndocker run -it ghcr.io/powershellweb/websocket\n~~~\n\n### Installing and Importing\n\n~~~PowerShell\nInstall-Module WebSocket -Scope CurrentUser -Force\nImport-Module WebSocket -Force -PassThru\n~~~\n\n### Get-WebSocket\n\nTo connect to a websocket and start listening for results, use [Get-WebSocket](Get-WebSocket.md)\n\n~~~PowerShell\n# Because get is the default verb, we can just say `WebSocket`\n# The `-Watch` parameter will continually watch for results\nwebsocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch\n~~~\n\nTo stop watching a websocket, simply stop the background job.\n\n### More Examples\n\n#### Get-WebSocket Example 1\n\n~~~powershell\n# Create a WebSocket job that connects to a WebSocket and outputs the results.\n$socketServer = Get-WebSocket -RootUrl \"http://localhost:8387/\" -HTML \"\u003ch1\u003eWebSocket Server\u003c/h1\u003e\"\n$socketClient = Get-WebSocket -SocketUrl \"ws://localhost:8387/\"\nforeach ($n in 1..10) { $socketServer.Send(@{n=Get-Random}) }\n$socketClient | Receive-Job -Keep\n~~~\n #### Get-WebSocket Example 2\n\n~~~powershell\n# Get is the default verb, so we can just say WebSocket.\n# `-Watch` will output a continous stream of objects from the websocket.\n# For example, let's Watch BlueSky, but just the text \nwebsocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch -Maximum 1kb |\n    % { \n        $_.commit.record.text\n    }\n~~~\n #### Get-WebSocket Example 3\n\n~~~powershell\n# Watch BlueSky, but just the text and spacing\n$blueSkySocketUrl = \"wss://jetstream2.us-$(\n    'east','west'|Get-Random\n).bsky.network/subscribe?$(@(\n    \"wantedCollections=app.bsky.feed.post\"\n) -join '\u0026')\"\nwebsocket $blueSkySocketUrl -Watch | \n    % { Write-Host \"$(' ' * (Get-Random -Max 10))$($_.commit.record.text)$($(' ' * (Get-Random -Max 10)))\"} -Max 1kb\n~~~\n #### Get-WebSocket Example 4\n\n~~~powershell\n# Watch continuously in a background job.\nwebsocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post\n~~~\n #### Get-WebSocket Example 5\n\n~~~powershell\n# Watch the first message in -Debug mode.  \n# This allows you to literally debug the WebSocket messages as they are encountered.\nwebsocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{\n    wantedCollections = 'app.bsky.feed.post'\n} -Max 1 -Debug\n~~~\n #### Get-WebSocket Example 6\n\n~~~powershell\n# Watch BlueSky, but just the emoji\nwebsocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail -Max 1kb |\n    Foreach-Object {\n        $in = $_\n        if ($in.commit.record.text -match '[\\p{IsHighSurrogates}\\p{IsLowSurrogates}]+') {\n            Write-Host $matches.0 -NoNewline\n        }\n    }\n~~~\n #### Get-WebSocket Example 7\n\n~~~powershell\n$emojiPattern = '[\\p{IsHighSurrogates}\\p{IsLowSurrogates}\\p{IsVariationSelectors}\\p{IsCombiningHalfMarks}]+)'\nwebsocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail |\n    Foreach-Object {\n        $in = $_\n        $spacing = (' ' * (Get-Random -Minimum 0 -Maximum 7))\n        if ($in.commit.record.text -match \"(?\u003e(?:$emojiPattern|\\#\\w+)\") {\n            $match = $matches.0                    \n            Write-Host $spacing,$match,$spacing -NoNewline\n        }\n    }\n~~~\n #### Get-WebSocket Example 8\n\n~~~powershell\nwebsocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch |\n    Where-Object {\n        $_.commit.record.embed.'$type' -eq 'app.bsky.embed.external'\n    } |\n    Foreach-Object {\n        $_.commit.record.embed.external.uri\n    }\n~~~\n #### Get-WebSocket Example 9\n\n~~~powershell\n# BlueSky, but just the hashtags\nwebsocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{\n    wantedCollections = 'app.bsky.feed.post'\n} -WatchFor @{\n    {$webSocketoutput.commit.record.text -match \"\\#\\w+\"}={\n        $matches.0\n    }                \n} -Maximum 1kb\n~~~\n #### Get-WebSocket Example 10\n\n~~~powershell\n# BlueSky, but just the hashtags (as links)\nwebsocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -WatchFor @{\n    {$webSocketoutput.commit.record.text -match \"\\#\\w+\"}={\n        if ($psStyle.FormatHyperlink) {\n            $psStyle.FormatHyperlink($matches.0, \"https://bsky.app/search?q=$([Web.HttpUtility]::UrlEncode($matches.0))\")\n        } else {\n            $matches.0\n        }\n    }\n}\n~~~\n #### Get-WebSocket Example 11\n\n~~~powershell\nwebsocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -WatchFor @{\n    {$args.commit.record.text -match \"\\#\\w+\"}={\n        $matches.0\n    }\n    {$args.commit.record.text -match '[\\p{IsHighSurrogates}\\p{IsLowSurrogates}]+'}={\n        $matches.0\n    }\n}\n~~~\n #### Get-WebSocket Example 12\n\n~~~powershell\n# We can decorate a type returned from a WebSocket, allowing us to add additional properties.\n~~~\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowershellweb%2Fwebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowershellweb%2Fwebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowershellweb%2Fwebsocket/lists"}