Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PowerShell examples #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/powershell/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This examples directory shows some examples written in PowerShell.

On Windows, note that each .ps1 file also requires a .cmd file to launch it.
The WebSocket should connect to ws://..../[example].cmd.
On Linux this is not required due to the shebang (#!/usr/bin/env pwsh).

You can also test the command files by running from the command line.
2 changes: 2 additions & 0 deletions examples/powershell/count.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -NoProfile -ExecutionPolicy Bypass %0\..\count.ps1
6 changes: 6 additions & 0 deletions examples/powershell/count.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env pwsh

for ($i = 1 ; $i -le 10; $i++) {
Write-Host $i
Start-Sleep -Milliseconds 500
}
2 changes: 2 additions & 0 deletions examples/powershell/dump-env.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -NoProfile -ExecutionPolicy Bypass %0\..\dump-env.ps1
45 changes: 45 additions & 0 deletions examples/powershell/dump-env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env pwsh

# Standard CGI(ish) environment variables, as defined in
# http://tools.ietf.org/html/rfc3875
$varNames = @(
"AUTH_TYPE",
"CONTENT_LENGTH",
"CONTENT_TYPE",
"GATEWAY_INTERFACE",
"PATH_INFO",
"PATH_TRANSLATED",
"QUERY_STRING",
"REMOTE_ADDR",
"REMOTE_HOST",
"REMOTE_IDENT",
"REMOTE_PORT",
"REMOTE_USER",
"REQUEST_METHOD",
"REQUEST_URI",
"SCRIPT_NAME",
"SERVER_NAME",
"SERVER_PORT",
"SERVER_PROTOCOL",
"SERVER_SOFTWARE",
"UNIQUE_ID",
"HTTPS"
)

$environmentVariables = [Environment]::GetEnvironmentVariables()

foreach ($key in $varNames) {
$value = $environmentVariables.Item($key)
if ([string]::IsNullOrEmpty($value)) {
$value = "<unset>"
}
Write-Host "$key=$value"
}

# Additional HTTP headers
foreach ($item in $environmentVariables.GetEnumerator()) {
$key, $value = $item.Key, $item.Value
if ($key.StartsWith("HTTP_")) {
Write-Host "$key=$value"
}
}
2 changes: 2 additions & 0 deletions examples/powershell/greeter.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -NoProfile -ExecutionPolicy Bypass %0\..\greeter.ps1
7 changes: 7 additions & 0 deletions examples/powershell/greeter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env pwsh

# For each line FOO received on STDIN, respond with "Hello FOO!".
while ($true) {
$line = Read-Host
Write-Host "Hello $line!"
}