Skip to content

Instantly share code, notes, and snippets.

@mickert
Last active September 6, 2026 21:43
Show Gist options
  • Select an option

  • Save mickert/d76e6a710a6cafb5b631049f6aa917e4 to your computer and use it in GitHub Desktop.

Select an option

Save mickert/d76e6a710a6cafb5b631049f6aa917e4 to your computer and use it in GitHub Desktop.
Run any .ps1 PowerShell script within Action1 using a safe wrapper generator with AST-based param detection and Base64 embedding. (c) 2026 Michel Sijmons - https://mickert.dev - License: Apache 2.0

PowerShell License Status Windows Action1

A robust PowerShell tool that automatically generates Action1-compatible wrapper scripts for existing .ps1 files.
The generated wrapper safely bypasses @Action1Corp’s script-flattening, parameter-injection quirks, and syntax corruption by embedding the original script as Base64 and reconstructing it at runtime.

This enables any PowerShell script - including complex installers, automation tools, and enterprise logic - to run reliably inside Action1.

So now it’s not just Action1: Patching That Just Works, but also Action1: Scripts That Just Work, thanks to ZyntriOps (comming soon).

Download URL: https://gists.mickert.dev/d76e6a710a6cafb5b631049f6aa917e4#file-new-a1wrapper-ps1
Latest README: https://gists.mickert.dev/d76e6a710a6cafb5b631049f6aa917e4#file-readme-md


⚡ Quick Start

Generate a wrapper for an existing script

.\New-A1Wrapper.ps1 -InputScriptPath .\MyScript.ps1

Generate a wrapper with a custom output path

.\New-A1Wrapper.ps1 -InputScriptPath .\MyScript.ps1 -OutputWrapperPath .\Wrapped.ps1

Run the generated wrapper inside Action1

Just paste the wrapper into an Action1 "Run PowerShell Script" job - no changes needed.


✨ Features

  • AST-based parameter discovery
    Automatically extracts the top-level param() block using the PowerShell parser, even in scripts with PSScriptInfo headers, CmdletBinding, or nested scopes.

  • Action1-safe parameter handling
    Converts Action1’s injected variables (${ParamName}) into real PowerShell variables and normalizes boolean-like values.

  • Base64 embedding
    The original script is embedded as Base64 and reconstructed at runtime, making it immune to Action1’s script flattening and syntax corruption.

  • Consistent logging
    The wrapper logs:

    • the wrapper banner
    • the original script name
    • all arguments as JSON
    • a timestamped execution line
  • Automatic output path
    If no output path is provided, the wrapper is written to:

    <InputScriptPath>_Action1-wrapper.ps1
    
  • No param(), no $args, no multiline comments
    The wrapper avoids all constructs that Action1 breaks.

  • Production-ready
    Designed for enterprise automation, RMM platforms, and CI/CD pipelines.


🧠 How It Works

The generator performs the following steps:

  1. Resolves the input script path to an absolute path (required for AST + file IO).
  2. Parses the script using the PowerShell AST engine.
  3. Extracts the top-level param() block (ignoring functions/classes).
  4. Base64-encodes the entire original script.
  5. Generates a wrapper that:
    • reads Action1-injected variables
    • normalizes boolean-like values
    • builds a hashtable of arguments
    • logs execution metadata
    • decodes the Base64 script into $env:TEMP
    • executes the script with splatting
    • returns the original exit code

The result is a wrapper that runs reliably inside Action1, regardless of how complex the original script is.


🚀 Usage Examples

Wrap a script with parameters

.\New-A1Wrapper.ps1 -InputScriptPath .\ZyntriOps-SmartmontoolsInstaller.ps1

Wrap a script without parameters

Works too - the wrapper simply passes an empty argument set.

Wrap a script in another directory

.\New-A1Wrapper.ps1 -InputScriptPath C:\Scripts\Deploy.ps1

Wrap and save to a specific location

.\New-A1Wrapper.ps1 -InputScriptPath .\Deploy.ps1 -OutputWrapperPath .\Deploy-A1.ps1

📦 Wrapper Output Example

When executed inside Action1, the wrapper prints:

ZyntriOps Action1 PowerShell Wrapper
Licensed under Apache License 2.0
Copyright (c) 2026 Michel Sijmons
Wrapper generator download: https://gists.mickert.dev/

[2026-03-04T12:56:15.2559329+01:00] Executing wrapped script 'ZyntriOps-SmartmontoolsInstaller.ps1' with arguments: {"Cleanup":true,"Json":true}

This makes debugging and auditing extremely easy.


🛠️ Requirements

  • Windows 10/11 or Windows Server 2016+
  • PowerShell 5.1 or PowerShell 7+
  • Administrator privileges (only required if the wrapped script needs it)
  • Action1 RMM (for execution)

📁 Wrapper Structure

The generated wrapper contains:

Section Purpose
ZyntriOps banner Branding + licensing
Action1 variable import Reads ${ParamName}
Boolean normalization Converts "1"/"0" to $true/$false
Argument hashtable Builds splatting dictionary
Logging Timestamp + JSON args
Base64 decode Writes original script to $env:TEMP
Execution Runs original script with & $scriptPath @callArgs
Exit code propagation Returns original exit code

🧪 Test Matrix Summary

Scenario Result
Script with PSScriptInfo ✔
Script with CmdletBinding ✔
Script with nested functions ✔
Script with multiple param() blocks ✔ (top-level only)
Script with no parameters ✔
Script with complex logic ✔
Action1 flattening ✔
Action1 variable injection ✔
Action1 syntax corruption ✔ (Base64 bypass)

📜 License (Apache 2.0)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

👋 Hey visitor - Michel here

If this tool saved you time, solved a headache, or helped you automate something cleanly inside Action1, consider supporting my work:

Your support helps me build more tools like this.

Kind regards,
Michel Sijmons
https://mickert.dev

<#PSScriptInfo
.VERSION 1.0.0
.GUID 2c7b0e5a-1c3d-4a7f-9f0f-9b8c2f7d2b11
.AUTHOR Michel Sijmons (ZyntriOps)
.COMPANYNAME ZyntriOps
.COPYRIGHT Copyright (c) 2026 Michel Sijmons - https://mickert.dev
.LICENSEURI http://www.apache.org/licenses/LICENSE-2.0
.PROJECTURI https://zyntriops.com
.TAGS action1;wrapper;automation;zyntriops;powershell
#>
<#
.SYNOPSIS
Generates an Action1-compatible wrapper for an existing PowerShell script.
.DESCRIPTION
This tool reads an existing PowerShell script, extracts the top-level param()
block using the PowerShell AST parser (ignoring param() blocks inside functions,
classes, or nested scopes), Base64-encodes the original script, and generates
a fully Action1-compatible wrapper script.
The wrapper:
- Reads Action1-injected variables (${ParamName})
- Normalizes boolean-like values ("1" → $true, "0" → $false)
- Logs execution with timestamp and JSON argument list
- Decodes the Base64-embedded original script into $env:TEMP
- Executes the original script with splatted arguments
- Exits with the original script's exit code
The wrapper is designed to survive Action1’s script flattening, variable
injection, and syntactic corruption. It avoids param(), $args, multiline
comments, and any constructs that Action1 may break.
.PARAMETER InputScriptPath
Path to the original PowerShell script to wrap.
.PARAMETER OutputWrapperPath
Optional. Path where the wrapper script will be written.
If omitted, the wrapper will be written to:
<InputScriptPath>_Action1-wrapper.ps1
.EXAMPLE
PS> .\New-A1Wrapper.ps1 -InputScriptPath .\MyScript.ps1
.EXAMPLE
PS> .\New-A1Wrapper.ps1 -InputScriptPath .\MyScript.ps1 -OutputWrapperPath .\Wrapped.ps1
.NOTES
Author : Michel Sijmons (ZyntriOps) - https://mickert.dev/
License : Apache License 2.0
Version : 1.0.0
.LINK
https://gists.mickert.dev/d76e6a710a6cafb5b631049f6aa917e4#file-new-a1wrapper-ps1
#>
# =====================================================================
# NOTICE
# =====================================================================
# This script is part of the ZyntriOps Toolkit.
# Developed by Michel Sijmons.
# Copyright (c) 2026 Michel Sijmons and licensed under the
# Apache License, Version 2.0. See License section below.
#
# For more information, visit: https://zyntriops.com
# =====================================================================
# DISCLAIMER & LICENSE
# =====================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# DISCLAIMER:
# This script is provided "as-is" without any warranties or guarantees.
# Use at your own risk. The author assumes no liability for any damages,
# data loss, misconfiguration, or operational impact resulting from the
# use of this script. Always test in a controlled environment before
# deploying to production.
# =====================================================================
# COPYRIGHT
# =====================================================================
# Copyright (c) 2026 Michel Sijmons
# All rights reserved.
param(
[Parameter(Mandatory)]
[string]$InputScriptPath,
[string]$OutputWrapperPath
)
function Get-Timestamp {
(Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffffffK")
}
function Get-TopLevelParamBlockAST {
param([string]$Path)
$resolved = (Resolve-Path $Path).ProviderPath
$errors = $null
$tokens = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile(
$resolved, [ref]$tokens, [ref]$errors
)
# Find all ParamBlockAst nodes
$paramBlocks = $ast.FindAll({
param($node)
$node -is [System.Management.Automation.Language.ParamBlockAst]
}, $true)
foreach ($pb in $paramBlocks) {
# Skip param() inside functions
if ($pb.Parent.Parent -is [System.Management.Automation.Language.FunctionDefinitionAst]) {
continue
}
# Skip param() inside classes
if ($pb.Parent.Parent -is [System.Management.Automation.Language.TypeDefinitionAst]) {
continue
}
return $pb
}
return $null
}
# Validate input
if (-not (Test-Path $InputScriptPath)) {
throw "Input script not found: $InputScriptPath"
}
# Determine output path if omitted
if (-not $OutputWrapperPath) {
$OutputWrapperPath = "${InputScriptPath}_Action1-wrapper.ps1"
}
# Resolve input path for both AST and file IO
$inputPathInfo = (Resolve-Path $InputScriptPath)
$inputScriptName = (Get-Item -LiteralPath $inputPathInfo).Name
$resolvedInputPath = $inputPathInfo.ProviderPath
# Parse AST
$pb = Get-TopLevelParamBlockAST -Path $resolvedInputPath
if (-not $pb) {
throw "No top-level param() block found in $InputScriptPath"
}
$paramNames = $pb.Parameters.Name.VariablePath.UserPath
if ($paramNames.Count -eq 0) {
throw "No parameters found in top-level param() block."
}
# Base64 encode original script
$bytes = [System.IO.File]::ReadAllBytes($resolvedInputPath)
$base64 = [Convert]::ToBase64String($bytes)
# Build wrapper
$wrapper = @()
# Banner
$wrapper += '# ZyntriOps Action1 PowerShell Wrapper'
$wrapper += '# Copyright (c) 2026 Michel Sijmons'
$wrapper += '# Licensed under Apache License 2.0'
$wrapper += '# Wrapper generator download: https://gists.mickert.dev/d76e6a710a6cafb5b631049f6aa917e4#file-new-a1wrapper-ps1'
$wrapper += '#'
$wrapper += "# wrapped original script: ${inputScriptName}"
$wrapper += ''
# Read Action1 variables
$wrapper += '# Read Action1-injected variables'
foreach ($p in $paramNames) {
$wrapper += '$' + $p + ' = ${' + $p + '}'
}
$wrapper += ''
$wrapper += '# Normalize boolean-like values'
foreach ($p in $paramNames) {
$wrapper += "if (`$$p -eq '1') { `$$p = `$true } elseif (`$$p -eq '0') { `$$p = `$false }"
}
$wrapper += ''
$wrapper += '# Build callArgs hashtable'
$wrapper += '$callArgs = @{}'
foreach ($p in $paramNames) {
$wrapper += "if (`$$p -ne '' -and `$$p -ne `$null) { `$callArgs['$p'] = `$$p }"
}
$wrapper += ''
$wrapper += ''
$wrapper += '# Log execution'
$wrapper += '$jsonArgs = ($callArgs | ConvertTo-Json -Compress)'
$wrapper += 'Write-Host "ZyntriOps Action1 PowerShell Wrapper"'
$wrapper += 'Write-Host "Licensed under Apache License 2.0"'
$wrapper += 'Write-Host "Copyright (c) 2026 Michel Sijmons"'
$wrapper += 'Write-Host "Wrapper generator download: https://gists.mickert.dev/d76e6a710a6cafb5b631049f6aa917e4#file-new-a1wrapper-ps1"'
$wrapper += 'Write-Host ""'
$wrapper += '$ts = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffffffK")'
$wrapper += 'Write-Host "[$ts] Executing wrapped script ''' + $inputScriptName + ''' with arguments: $jsonArgs"'
$wrapper += ''
$wrapper += '# Decode original script'
$wrapper += '$scriptPath = "$env:TEMP\Action1WrappedScript.ps1"'
$wrapper += '$base64 = "' + $base64 + '"'
$wrapper += '[IO.File]::WriteAllBytes($scriptPath, [Convert]::FromBase64String($base64))'
$wrapper += ''
$wrapper += '# Execute original script'
$wrapper += '& $scriptPath @callArgs'
$wrapper += 'exit $LASTEXITCODE'
# Write wrapper
Set-Content -Path $OutputWrapperPath -Value ($wrapper -join "`r`n") -Encoding UTF8
Write-Host "Wrapper generated at: $OutputWrapperPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment