Invoke-AsCurrentUser_WithArgs

1.1.0

Execute PowerShell scriptblocks in the context of the currently logged-in user from a SYSTEM context. Ideal for Intune deployments, SCCM task sequences, and scheduled tasks. Supports argument passing, transcript capture, stream capture, and configurable timeouts.

Minimum PowerShell version

5.1

Installation Options

Copy and Paste the following command to install this package using PowerShellGet More Info

Install-Module -Name Invoke-AsCurrentUser_WithArgs

Copy and Paste the following command to install this package using Microsoft.PowerShell.PSResourceGet More Info

Install-PSResource -Name Invoke-AsCurrentUser_WithArgs

You can deploy this package directly to Azure Automation. Note that deploying packages with dependencies will deploy all the dependencies to Azure Automation. Learn More

Manually download the .nupkg file to your system's default download location. Note that the file won't be unpacked, and won't include any dependencies. Learn More

Owners

Copyright

(c) 2025-2026. All rights reserved.

Package Details

Author(s)

  • Harze2k

Tags

RunAsUser Intune SCCM SYSTEM UserContext Deployment Windows

Functions

Invoke-AsCurrentUser_WithArgs Serialize-Object Deserialize-Object Get-RunAsUserCSharpSource

PSEditions

Desktop Core

Dependencies

This module has no dependencies.

Release Notes

## Version 1.1.0
- Replaced all throw statements with Write-Error and graceful return patterns to prevent script termination
- Improved error handling: functions now return $null on failure instead of throwing
- Added consistent ExecutionSuccess property to all result output paths
- Stream capture results (StdOut, StdErr, Warnings, Verbose) now always present when -CaptureStreams is used (empty string instead of missing)
- Improved parameter validation error messages with Write-Error instead of silent Write-Warning
- Updated function descriptions and synopsis for clarity
- Fixed WorkingDirectory parameter validation to handle empty strings properly
- Added error result output on Add-Type compilation failure
- Improved timeout handling to return structured error objects instead of throwing
- Backup log file naming now uses timestamp instead of random number for easier troubleshooting

## Version 1.0.0
- Initial release
- Execute scriptblocks as currently logged-in user
- Pass arguments/variables to scriptblocks
- Capture transcript and execution results
- Support for PowerShell 5.1 and 7+
- Configurable timeout handling
- Optional stream capture (stdout/stderr)

FileList

Version History

Version Downloads Last updated
1.1.0 (current version) 77 3/13/2026
1.0.0 808 12/1/2025