Examples
Get-Process | Where-Object {$_.Name -like "idea*"}
Get-Process | Where-Object {$_.Name -like "idea*"} | Format-Table
Get-Process | Where-Object {$_.Name -like "idea*"} | ConvertTo-Json
# Format to JSON
Get-Process | ConvertTo-Json
# can use JQ as well:
Get-Process | ConvertTo-Json | jq -c
From Hello World
Go to text →
On linux to create file that will execute by powershell:
#!/usr/bin/env pwsh
Write-Host "Hello from PowerShell!"
From Call Bash in Parallel from Powershell
Go to text →
#!/usr/bin/env pwsh
Write-Host "Hello from PowerShell!"
1..2 | ForEach-Object -Parallel {
bash /Users/nkondrat/vintrin-env/.tmp/scratches/scratch.sh $_ ABC
} -ThrottleLimit 1000
From Error Handling Non Zero Return Codes
Go to text →
#!/usr/bin/env pwsh
# Can make any non zero exit codes be treated as proper termination errors
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
function Main {
param($arg1, $arg2)
Write-Host "Starting script..."
try {
# Can invoke bash scripts,
& $env:ISSH
Write-Host "Command succeeded"
}
catch {
# If bash scripts fail we can have a proper catch block
Write-Host "CAUGHT ERROR: $($_.Exception.Message)"
}
Write-Host "Script completed."
}
# Invoke it at the end
Main -arg1 "value1" -arg2 "value2"
Children
Backlinks