# 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](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:

```powershell
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.

## Related Content

- **[PsExec - Sysinternals | Microsoft Learn](https://docs.microsoft.com/en-us/sysinternals/downloads/psexec)**
- **[Script Best Practices](https://kb.filewave.com/books/filewave-general-info/page/script-best-practices "Script Best Practices")**

## Digging Deeper

### PsExec Switches

- `-i`: runs the process interactively in the specified or current console session.
- `-s`: runs the process as the local SYSTEM account.
- `-d`: starts the process without waiting for it to finish. Omit this switch when you need to read script output during testing.
- `-accepteula`: accepts the PsExec license agreement for the test run.

### 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.

```powershell
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.