liveBook · Manning

System context

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

A system context is an operating-system execution context associated with a system-managed identity rather than an interactive user.

A system context runs a script under the operating system’s system account instead of an interactive user. It suits unattended automation when the task needs machine-level access or should avoid storing a password. section 4.1.3 section 11.4.2

Choose the system context deliberately:

  • Use it when elevated permissions or machine-level locations are required, such as Program Files, Program Data, or the machine registry. section 11.4.2
  • Avoid it for user-specific settings because the system account lacks the interactive user profile and HKCU access. section 11.4.2
  • Test the commands first as an administrator, then under a standard user and the system context; combine execution methods when necessary. section 11.4.2

Unattended SQL health check

When SQL Server uses Windows domain authorization, schedule the health-check script to run as the authorized account. Alternatively, run it locally on the database server under the system context, avoiding a stored username and password while restricting execution to that server. section 4.1.3

.\git-install.ps1 -branch 'main'
Chocolatey v0.12.1
Installing the following packages:
git.install
By installing, you accept licenses for the packages.
Progress: Downloading git.install 2.35.1.2... 100%
 
chocolatey-core.extension v1.3.5.1 [Approved]
chocolatey-core.extension package files install completed. Performing ot...
Installed/updated chocolatey-core extensions.
The install of chocolatey-core.extension was successful.
Software installed to 'C:\ProgramData\chocolatey\extensions\chocola...
 
git.install v2.35.1.2 [Approved]
git.install package files install completed. Performing other installa...
Using Git LFS
Installing 64-bit git.install...
git.install has been installed.
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The install of git.install was successful.
Software installed to 'C:\Program Files\Git\'
 
Chocolatey installed 2/2 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Inspect the system-context Git installation output produced through Invoke-CommandAs; related listings show the resulting system-level Git configuration. section 11.4.2

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Compares resource access and testing behavior, but stops short of explaining operating-system implementation internals.
Examples
Uses a SQL health check and a Chocolatey-based Git installation to demonstrate unattended execution and configuration validation.
What it assumes
Assumes familiarity with PowerShell scripts, scheduled execution, permissions, and Windows configuration scopes.
What you can do after
Operate/configure scripts under the system account and test whether permissions, profiles, and machine-level settings behave as intended.
How it connects
Connects system accounts with user contexts, administrator contexts, user profiles, machine registry, UAC, and delegated permissions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.