powershell7

Public

PowerShell7 is an LM Studio plugin that lets local models run real PowerShell 7 commands and managed .ps1 scripts through pwsh, with practical safety controls such as timeouts, output limits, risk checks, confirmation gates, and audit logging.

149 Downloads

1 star

README

PowerShell7

PowerShell7 is an LM Studio plugin that lets local models run real PowerShell 7 commands and managed .ps1 scripts through pwsh, with practical safety controls such as timeouts, output limits, risk checks, confirmation gates, and audit logging.

Overview

PowerShell7 uses real PowerShell 7 through pwsh.exe on Windows or pwsh on other platforms. It does not use Windows PowerShell 5.1, and it intentionally rejects powershell.exe because that executable is not PowerShell 7.

The plugin supports two execution modes:

  • Inline PowerShell 7 commands run through pwsh.
  • Managed .ps1 scripts created, executed, and deleted inside the configured scripts directory.

Important Safety Warning

This plugin gives local models command execution ability. It is not an OS sandbox. Commands and scripts run with the current user's permissions and can read, write, modify, or delete anything that user account can access.

Review commands and scripts before allowing high-risk execution. Do not use this plugin with untrusted models, untrusted prompts, or workflows where command execution should not be available.

Features

  • Run inline PowerShell 7 commands.
  • Create managed .ps1 script files.
  • Run managed .ps1 script files.
  • Delete managed .ps1 script files.
  • Diagnose PowerShell 7 path, version, and configuration.
  • View current plugin configuration.
  • LM Studio UI configuration.
  • Automatic or manual PowerShell 7 path selection.
  • Timeout handling.
  • stdout and stderr byte limits.
  • Output truncation metadata.
  • ANSI and CLIXML cleanup.
  • Risk scanner.
  • High-risk confirmation.
  • Catastrophic command blocking.
  • JSONL audit logging.

Tools

diagnose_powershell7

Diagnoses PowerShell path resolution, version, edition, working directory, and active configuration.

get_powershell7_config

Returns the current plugin configuration as seen by LM Studio without running PowerShell.

run_powershell7

Runs an inline PowerShell 7 command.

create_ps1_file

Creates or overwrites a managed .ps1 file inside the configured scripts directory.

run_ps1_file

Runs a managed .ps1 file from the configured scripts directory.

delete_ps1_file

Deletes a managed .ps1 file from the configured scripts directory.

Configuration in LM Studio

Configuration is done through LM Studio's plugin settings UI. Environment variables are available only as an advanced fallback for local development or non-standard runtime setups.

FieldDescription
PowerShell 7 Path ModeSelects automatic or manual PowerShell 7 path resolution. Automatic mode is the default.
Manual PowerShell 7 PathUsed only in manual mode. Example: C:\Program Files\PowerShell\7\pwsh.exe.
Default Timeout SecondsDefault timeout for inline commands and managed scripts.
Maximum Timeout SecondsUpper bound for requested command or script timeouts.
Stdout Max BytesMaximum stdout bytes returned to the model.
Stderr Max BytesMaximum stderr bytes returned to the model.
Scripts DirectoryDirectory where managed .ps1 files are stored.
Audit Log PathJSONL audit log path.
Strip ANSI OutputRemoves ANSI escape sequences from returned output.
Use Normal PowerShell Error ViewUses PowerShell's normal error view for cleaner error output.

Automatic mode searches for pwsh.exe or pwsh. Manual mode lets the user specify an explicit PowerShell 7 path, such as:

C:\Program Files\PowerShell\7\pwsh.exe

The manual path must point to pwsh.exe or pwsh. powershell.exe is intentionally rejected.

Advanced Environment Variable Fallback

LM Studio's plugin settings UI is the main configuration method. These environment variables are intended only as an advanced fallback:

POWERSHELL7_PATH_MODE=auto|manual
POWERSHELL7_MANUAL_PATH=C:\Program Files\PowerShell\7\pwsh.exe
POWERSHELL7_DEFAULT_TIMEOUT_SECONDS=30
POWERSHELL7_MAX_TIMEOUT_SECONDS=300
POWERSHELL7_STDOUT_MAX_BYTES=65536
POWERSHELL7_STDERR_MAX_BYTES=65536
POWERSHELL7_SCRIPTS_DIR=.powershell7-scripts
POWERSHELL7_AUDIT_LOG=.powershell7-audit.log

Installation / Development

npm install
npm run typecheck
npm run build
npm run dev

Publishing

npm run push

or:

lms push

Example Usage

Inline command:

$PSVersionTable | ConvertTo-Json -Depth 4

List files:

Get-ChildItem

Create a script:

{
  "fileName": "hello.ps1",
  "content": "Write-Output \"Hello from PowerShell7\"",
  "overwrite": true
}

Run a script:

{
  "fileName": "hello.ps1"
}

Delete a script:

{
  "fileName": "hello.ps1"
}

Safety Model

The risk scanner assigns commands and scripts to practical risk levels:

  • low: normal read/output commands.
  • medium: file writes, downloads, installs, process actions, and non-recursive deletion.
  • high: system policy, service, user, or security-sensitive changes that require confirmation.
  • blocked: catastrophic or clearly dangerous commands.

Blocked examples include:

  • Clear-Disk
  • Format-Volume
  • Remove-Partition
  • Dangerous recursive force deletion near root, system, or user directories.
  • Obvious credential dumping terms.
  • Security-disabling commands.

The scanner is a guardrail, not a guarantee. Users should still inspect commands and managed scripts before execution.

Limitations

  • Risk scanner is best-effort.
  • Not a full sandbox.
  • Runs with the current user's permissions.
  • PowerShell is powerful and can be obfuscated.
  • Users are responsible for reviewing commands and scripts.
  • Use least-privileged Windows accounts for safer operation.

Manual Test Checklist

  • npm install
  • npm run typecheck
  • npm run build
  • npm run dev
  • Confirm LM Studio plugin settings UI appears
  • Run diagnose_powershell7
  • Run get_powershell7_config
  • Test inline Write-Host / Write-Output
  • Test real stderr with Write-Error
  • Test .ps1 create/run/delete lifecycle
  • Test high-risk confirmation
  • Test blocked command
  • Test path traversal rejection
  • Test truncation metadata

License

Apache-2.0