5.2 KiB
Repository Guidance
RMM script execution model
This is the required convention for new RMM scripts. Read both
Install-MicrosoftOffice365.ps1 and its
rmm/Install-MicrosoftOffice365.ps1 caller
as the reference implementation before designing script inputs or a loader.
Scripts in this repository are generally executed by a small caller script in the RMM. The caller first downloads and dot-sources Tools.ps1 from the public repository URL:
. $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1')))
The caller then invokes Run-Script, passing the repository script's filename without the .ps1 extension:
Run-Script -LivePSScript Create-BatteryReport
The live-script calling convention preserves the caller's PowerShell context so
the downloaded core can read the caller's variables. Dot-sourcing (. $ScriptFile
or . $ScriptBlock) is the standard way to provide this shared scope. Keep the
core logic in version control so repository updates take effect without replacing
each RMM caller. Run-Script has separate execution branches; verify variable
visibility against the actual helper when changing a loader.
When a repository script needs RMM-provided input, define the variable in the RMM caller before calling Run-Script. The downloaded core reads that variable directly from the inherited scope.
When changing Run-Script or scripts invoked through it, preserve this shared-scope behavior unless the change explicitly includes migrating all affected RMM callers.
RMM inputs are caller variables containing strings
- Define/configure operator inputs in the RMM shim, before loading the core. The RMM supplies strings only, even for boolean, integer, and list settings.
- The core reads inherited variables, as the Office installer does. Do not
introduce script-level
param(...)blocks, command-line flags, or a public-Optionshashtable for RMM settings. Helper functions inside a script may still declare parameters for their internal interfaces. - Do not pass RMM settings through
Run-Script -Arguments. UseRun-Script -LivePSScript <filename-without-extension>with caller variables already defined. Do not add a new PowerShell process/runspace for convenience: it does not inherit those variables. If a new process is required, explicitly transfer the inputs, as the Office installer does for its native-host relaunch. - Never overwrite values injected by the RMM. When defaults are appropriate,
distinguish a missing variable from a supplied blank/false value. A core can
use
Get-Variable -Name ... -ErrorAction SilentlyContinueto collect optional inputs without redefining them or relying on a script parameter block. - Convert boolean strings with
ConvertTo-RmmBooleanfromTools.ps1. Never use[bool]$Text: a nonempty string such as'false'casts to true. - Parse semicolon-separated list strings with
@(ConvertTo-RmmList -Value $Text)fromTools.ps1. The helper trims items and removes empty entries;@(...)ensures an array for zero/one/many items. It does not validate or resolve paths. Validate share names/paths in the core according to the workload. Keep reusable conversion helpers inTools.ps1; do not duplicate their implementation in individual scripts. - Parse integer strings explicitly and validate the allowed range. Keep the original caller values intact and use separate normalized internal values.
- For a permanent endpoint shim launched later by a backup agent, persist its configured string values in that shim. Variables injected into an earlier RMM process do not survive into the backup agent's new PowerShell process.
Example values in a caller (the RMM may inject these rather than assigning them in the script):
$QuickBooksShareNames = 'QBData;QBArchive'
$QuickBooksForceClose = 'true'
$QuickBooksGraceSeconds = '60'
Tools loading and verification
- Download
Tools.ps1live when needed. Do not cacheTools.ps1or its helper definitions, or introduce an offline Tools fallback. This is an explicit repository preference; the cloud-backup workflow requires network access. - Set TLS 1.2 before the first HTTPS download on Windows PowerShell 5.
- Normally dot-source live
Tools.ps1as shown above, then callRun-Script. The QuickBooks permanent backup shim has a documented specialized loader: it downloads Tools live and dot-sources only its two conversion definitions to avoid running unrelated setup/logging during backup. This is not a reason to replace the standard loader in other scripts. Each QuickBooks shim downloads its matching root script (Stop or Start), which downloads the shared routines fromresources/quickbooks/QuickBooksBackup.ps1. All code is fetched live; only recovery state/logs persist. Start must not call a local Stop shim or use a cached Stop script in a hidden restore mode. - Use focused Windows PowerShell 5 tests to verify actual shim-to-core input visibility, string-to-boolean/list conversion, and exit-code propagation when changing these boundaries. Mock downloads and disruptive actions during tests.