Invoke-AsCurrentUser_WithArgs.psd1

@{
    # Script module file associated with this manifest
    RootModule           = 'Invoke-AsCurrentUser_WithArgs.psm1'
    # Version number
    ModuleVersion        = '1.1.1'
    # Supported PSEditions
    CompatiblePSEditions = @('Desktop', 'Core')
    # ID used to uniquely identify this module
    GUID                 = 'f7a3b2c1-8d4e-4f6a-9b5c-1e2d3f4a5b6c'
    # Author
    Author               = 'Harze2k'
    # Company or vendor
    CompanyName          = 'Community'
    # Copyright statement
    Copyright            = '(c) 2025-2026. All rights reserved.'
    # Description
    Description          = '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 required
    PowerShellVersion    = '5.1'
    # Functions to export from this module
    FunctionsToExport    = @(
        'Invoke-AsCurrentUser_WithArgs',
        'Serialize-Object',
        'Deserialize-Object',
        'Get-RunAsUserCSharpSource'
    )
    # Cmdlets to export
    CmdletsToExport      = @()
    # Variables to export
    VariablesToExport    = @()
    # Aliases to export
    AliasesToExport      = @()
    # Private data to pass to the module
    PrivateData          = @{
        PSData = @{
            # Tags applied to this module for module discovery
            Tags                       = @('RunAsUser', 'Intune', 'SCCM', 'SYSTEM', 'UserContext', 'Deployment', 'Windows')
            # License URI
            LicenseUri                 = 'https://github.com/Harze2k/Shared-PowerShell-Modules/blob/main/LICENSE'
            # Project URI
            ProjectUri                 = 'https://github.com/Harze2k/Shared-PowerShell-Modules/Invoke-AsCurrentUser_WithArgs'
            # Icon URI
            # IconUri = ''
            # Release notes
            ReleaseNotes               = @'
## Version 1.1.1
- FIXED: Get-SafeTempPath now prefers ProgramData\UserInvoke\Temp and explicitly grants Authenticated Users (Modify) on the exchange directory. Previously C:\Windows\Temp\UserInvoke was selected and write-tested in the CALLER's context (SYSTEM), but the helper runs as the TARGET USER who cannot access C:\Windows\Temp - every waiting call from SYSTEM to a standard user (or with -NonElevatedSession) failed with 'Timeout waiting for result file' because the helper could neither read data.json nor write result.json.
- NEW: -SessionTokenRetrySeconds parameter (default 15, 0 = previous fail-fast behavior). WTSQueryUserToken is retried within this window when no interactive session token exists yet (Win32 error 1008), which happens when the caller fires on a logon trigger seconds before winlogon publishes the token.
- IMPROVED: the result-file wait fails fast with an explanatory message when the helper process has exited without reporting back, instead of burning the full timeout and masking the cause.
- IMPROVED: exactly ONE catchable error per failure. Inner layers now Write-Warning and return structured results; previously their Write-Error calls were promoted to terminating errors under callers using -ErrorAction Stop, which skipped the documented structured return and produced 4-5 duplicate transcript entries per failure. Note: failures are now reported on the error stream even with -Quiet (-Quiet suppresses output, not failures).

## 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)
'@

            # Prerelease string
            # Prerelease = ''
            # Flag to indicate whether the module requires explicit user acceptance for install/update
            RequireLicenseAcceptance   = $false
            # External dependent modules
            ExternalModuleDependencies = @()
        }
    }
    # Help info URI
    HelpInfoURI          = 'https://github.com/Harze2k/Shared-PowerShell-Modules/Invoke-AsCurrentUser_WithArgs/wiki'
}