Invoke-CommandAs is a PowerShell module for testing commands and script blocks under Windows security contexts, including the system account. System execution differs from elevation: it cannot access the interactive user's profile or registry hive. section 11.4.2
Use it when automation must distinguish user-scoped and machine-scoped effects:
- Install the module in an elevated Windows PowerShell 5.1 prompt, import it, and invoke a script with -AsSystem. section 11.4.2
- Expect system execution to write machine resources while leaving user settings such as the default Git branch unchanged. section 11.4.2
- Refresh environment variables or reboot after installation before validating commands in a new PowerShell session. section 11.4.2
Run an installer as SYSTEM
Install-Module -Name Invoke-CommandAs Import-Module -Name Invoke-CommandAs Invoke-CommandAs -ScriptBlock { . C:\git-install.ps1 } -AsSystem
