A deliberately stripped-down PowerShell script interpreter, written in strict C89 for low-powered and vintage systems. It is not intended to be used as a feature-complete PowerShell runtime.
cmake -S . -B build/cmake
cmake --build build/cmake
ctest --test-dir build/cmake --output-on-failureRun a script or an inline command:
./build/cmake/picoposh script.ps1
./build/cmake/picoposh -c 'Write-Output "hello"'
./build/cmake/picoposh --versionA taste of the supported subset:
$src = "data.txt"
if (Test-Path $src) {
Get-ChildItem "." | Write-Output
Copy-Item $src "backup.txt"
Write-Output "done"
}picoposh is also a small static library. Include one header and run scripts from your own application, capturing or redirecting their output:
#include "picoposh.h"
char *out = NULL;
int code = pico_run_capture("Write-Output (2 + 3)\n", "job", &out, NULL);
puts(out); /* -> 5 */
pico_string_free(out);Link with CMake (find_package(picoposh) → picoposh::picoposh) or compile the sources directly. See docs/embedding.md and examples/embed.
- Language: string/integer literals,
$varassignment (from an expression or a pipeline),"$var"and"$( … )"string expansion, bare expression statements,Verb-Nouncommands with positional/named/switch parameters,|pipelines,if/elseif/else,foreach ($x in …),while,#comments. - Control flow:
if/elseif/else,foreach,while,for,break,continue. - User-defined
functions with positional and named params,param(...)blocks, typed ([int]$n) and default-valued ($n = 5) parameters, pipeline input (begin/process/endblocks with$_, or$input),$args,return, recursion, and local scope. switchstatements andtry/catch/finally+throwerror handling.- Expressions: integer (incl. hex
0xFF) and floating-point arithmetic+ - * / %, compound assignment+= -= *= /=and++/--, comparison-eq -ne -lt -le -gt -ge -like -match(regex), membership/type-contains -in -is -as, bitwise-band -bor -bxor -bnot -shl -shr, logical-and -or -not/!,$( … )subexpressions, member access$obj.Prop,.Count/.Lengthand string methods (.ToLower(),.Substring(),.Replace(), …), array literals1,2,3/@( … )with$a[0]indexing, hashtable literals@{ k = v }, and{ … }script blocks ($_inside), ranges1..10, and-join/-split. - Cmdlets:
Get-ChildItem,Copy-Item,Move-Item,Remove-Item,New-Item,Test-Path,Get-Item,Rename-Item,Get-Location,Set-Location,Push-Location,Pop-Location,Join-Path,Split-Path,Resolve-Path,Get-Content,Set-Content,Add-Content,Clear-Content,Out-File,Write-Output,Write-Error,Write-Host,Write-Warning,Out-Null,Out-String,Where-Object,ForEach-Object,Sort-Object,Measure-Object,Select-Object,Format-Table,Format-List,Group-Object,Compare-Object,Get-Unique,Tee-Object,New-Object,Get-Member,Get-Variable,Set-Variable,New-Variable,Select-String,Get-Date,ConvertTo-Json,ConvertFrom-Json,ConvertTo-Csv,ConvertFrom-Csv,Import-Csv,Export-Csv,Invoke-WebRequest,Get-Command,Get-Help,Import-Module. - Script modules via
Import-Module. - Everything outside the subset parses to a clear "not supported yet" error rather than misbehaving.