I am currently working on creating a GUI-based application that involves calling Start-Process with specific parameters. The application works as expected when executed in both PowerShell.exe and ISE. However, I am encountering a problem when attempting to wrap the scripts (TEST1.PS1 + TEST2.PS1 + Cred Module) into an executable using IExpress.
When I run the executable, I encounter a flashing screen with no visible output before the window closes. Interestingly, I don't receive any error messages in the output or the Event Viewer.
Here's a simplified version of the code I'm using:
TEST1.PS1
$userwho1 = whoami
Import-Module "$PSScriptRoot\CredentialManager.psm1"
$credential = Get-StoredCredential "MYADMIN"
$fileExists = Test-Path -Path "$PSScriptRoot\TEST2.ps1"
if ($fileExists) {
Write-Host "The file exists: $PSScriptRoot\TEST2.ps1"
$Release = "$PSScriptRoot\TEST2.ps1"
} else {
Write-Host "The file does not exist."
}
Start-Process -FilePath
'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
-WindowStyle hidden -ArgumentList "-executionpolicy bypass -File
$Release $userwho1" -Credential $credential -WorkingDirectory
'C:\Windows\System32'
Here is a screenshot confirming that the script is in place and detected at runtime.
My expectation is that Start-Process should call TEST2.PS1 (a user form) with the privileges of the MYADMIN domain user.
Additional Information:
PowerShell version: 5.1 I suspect that the issue might be related to how I'm wrapping the scripts using IExpress. Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you!