PowerShellでHello World

(20)
https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1
https://qiita.com/koyoru1214/items/721e528c86ee2baff871
http://nyoro2.net/wp/?p=269


apt update
apt install -y wget apt-transport-https software-properties-common
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt update
add-apt-repository universe
apt install -y powershell

pwsh -v

vim hello.ps1
Write-Host "Hello world!"

pwsh ./hello.ps1

--
vim web.ps1

$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://localhost:8080/")
try {
$listener.Start()
while ($true) {
$context = $listener.GetContext()
$response = $context.Response
$content = [System.Text.Encoding]::UTF8.GetBytes('hello world!')
$response.OutputStream.Write($content, 0, $content.Length)
$response.Close()
}
}
catch {
Write-Error($_.Exception)
}

pwsh ./web.ps1 &
curl http://localhost:8080/

 

(10)

wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt update
apt install -y powershell

pwsh -v

vim hello.ps1
Write-Host "Hello world!"

pwsh ./hello.ps1

--
vim web.ps1

$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://localhost:8080/")
try {
$listener.Start()
while ($true) {
$context = $listener.GetContext()
$response = $context.Response
$content = [System.Text.Encoding]::UTF8.GetBytes('hello world!')
$response.OutputStream.Write($content, 0, $content.Length)
$response.Close()
}
}
catch {
Write-Error($_.Exception)
}

pwsh ./web.ps1 &
curl http://localhost:8080/

(7)
https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1
https://qiita.com/koyoru1214/items/721e528c86ee2baff871
http://nyoro2.net/wp/?p=269

 

curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
yum install -y powershell

pwsh -v

vim hello.ps1
Write-Host "Hello world!"

pwsh ./hello.ps1

--
vim web.ps1

$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://localhost:8080/")
try {
$listener.Start()
while ($true) {
$context = $listener.GetContext()
$response = $context.Response
$content = [System.Text.Encoding]::UTF8.GetBytes('hello world!')
$response.OutputStream.Write($content, 0, $content.Length)
$response.Close()
}
}
catch {
Write-Error($_.Exception)
}

pwsh ./web.ps1 &
curl http://localhost:8080/

(2019)
https://github.com/PowerShell/PowerShell

$PSVersionTable

notepad hello.ps1
Write-Host "Hello world!"

.\hello.ps1

--
notepad web.ps1

$listener = New-Object Net.HttpListener
$listener.Prefixes.Add("http://localhost:8080/")
try {
$listener.Start()
while ($true) {
$context = $listener.GetContext()
$response = $context.Response
$content = [System.Text.Encoding]::UTF8.GetBytes('hello world!')
$response.OutputStream.Write($content, 0, $content.Length)
$response.Close()
}
}
catch {
Write-Error($_.Exception)
}


.\web.ps1 &
curl http://localhost:8080/