update M365 deployment script to try not to depend on previous deployments
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
|
||||
## RMM script execution model
|
||||
|
||||
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
|
||||
@@ -14,8 +19,72 @@ The caller then invokes `Run-Script`, passing the repository script's filename w
|
||||
Run-Script -LivePSScript Create-BatteryReport
|
||||
```
|
||||
|
||||
For a live PowerShell script without `-Arguments`, `Run-Script` downloads the target script and dot-sources it. This keeps the core script logic in version control, and changes pushed to the repository take effect in production without updating each RMM caller.
|
||||
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`. Because the target is dot-sourced into the caller's scope, it can read that variable directly.
|
||||
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 <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 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 5.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
Reference in New Issue
Block a user