Test PowerShell as SYSTEM with PsExec on Windows

What

FileWave runs Windows deployment scripts as the local SYSTEM account. Microsoft PsExec lets you test a PowerShell script in that same security context before deploying it through a Fileset or Custom Field.

When/Why

Current FileWave Windows clients are 64-bit. Test with 64-bit PowerShell unless you are reproducing a legacy 32-bit execution path. For script-based Custom Fields, the On Windows, run as 64-bit setting controls the PowerShell architecture. Testing as SYSTEM catches differences in permissions, profile paths, mapped drives, registry hives, and user-specific environment variables.

How

  1. Download PsExec from the Sysinternals Suite (https://docs.microsoft.com/en-us/sysinternals/downloads/psexec )

  2. Open a Command Prompt or PowerShell window with Administrator privileges

  3. Navigate to the folder where PsExec is located

  4. Use the following command to run the script as SYSTEM with 64-bit Windows PowerShell: PSEXEC -accepteula -i -s C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "path\to\script.ps1"

Example:

PSEXEC -accepteula -i -s C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\test\testscript.ps1"

To reproduce a known 32-bit execution path, use C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe instead.

Digging Deeper

PsExec Switches

Calling 64-bit PowerShell from a 32-bit process

Keep this compatibility pattern only for scripts that can still start in a 32-bit process and must relaunch themselves in 64-bit PowerShell. Sysnative bypasses Windows filesystem redirection from that 32-bit process.

If ( [IntPtr]::Size * 8 -ne 64 )
{
    C:\Windows\SysNative\WindowsPowerShell\v1.0\PowerShell.exe -File $MyInvocation.MyCommand.Path
}
Else
{
    # Add code here
}

The code checks the current process architecture. A 32-bit process relaunches the same script through Sysnative; a 64-bit process continues into the Else block.

Run the test on a representative Windows device, review the exit code and output, then pilot the FileWave deployment before expanding the association.


Revision #4
Created 2023-07-02 17:18:27 UTC by Josh Levitsky
Updated 2026-07-10 20:53:20 UTC by Josh Levitsky