# Repository Guidance ## RMM script execution model Target **Windows PowerShell 4.0** by default for new Windows RMM scripts. Put `#Requires -Version 4.0` in both the RMM caller and its downloaded core. Use 4.0-compatible syntax, cmdlets and .NET APIs throughout their execution path, including shared helpers. If a workload genuinely needs a newer version, document the dependency alongside its version requirement. This is the required convention for new RMM scripts. Read both [`Install-MicrosoftOffice365.ps1`](Install-MicrosoftOffice365.ps1) and its [`rmm/Install-MicrosoftOffice365.ps1`](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: ```powershell . $([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: ```powershell 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 `-Options` hashtable 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`. Use `Run-Script -LivePSScript ` 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 SilentlyContinue` to collect optional inputs without redefining them or relying on a script parameter block. - Convert boolean strings with **`ConvertTo-RmmBoolean` from `Tools.ps1`**. Never use `[bool]$Text`: a nonempty string such as `'false'` casts to true. - Parse semicolon-separated list strings with **`@(ConvertTo-RmmList -Value $Text)` from `Tools.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 in `Tools.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): ```powershell $QuickBooksShareNames = 'QBData;QBArchive' $QuickBooksForceClose = 'true' $QuickBooksGraceSeconds = '60' ``` ## Tools loading and verification - Download `Tools.ps1` live when needed. **Do not cache `Tools.ps1` or 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 4.0 and 5.x. - Normally dot-source live `Tools.ps1` as shown above, then call `Run-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 from `resources/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. - Test shim-to-core input visibility, string conversions, and exit-code propagation when changing these boundaries. Mock downloads and disruptive actions. For the 4.0 baseline, run on Windows PowerShell 4.0 when available. Otherwise check compatibility against the Server 2012 R2 / PowerShell 4.0 profile and run the focused tests on Windows PowerShell 5.1.