I have a cmd script (which will ultiamtely be a Task scheduler triggered task) that needs to start a new Powershell process as a different user to call an additional script, remote.ps1.
Explanation
The hierarchy is as follows:
1.0 - cmd file, runs powershell:
powershell -ExecutionPolicy Bypass -File %SCRIPT_DIR%\credential.ps1
2.1 - credential.ps1 creates a credential object from an encrypted pwd file of other user created via Powershell ISE Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File object
$username = "myuser"
$securestringpwd = Get-Content -Path "C:\Desktop\pwd" | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential $username, $securestringpwd
2.2 - ...calls a new powershell process at the end, to execute the remote.ps1 script with the additional arguments
$abc = "example1"
$def = "example2"
$dir = "$env:SCRIPT_DIR"
Start-Process powershell.exe -Credential $credential -ArgumentList @('-ExecutionPolicy"Bypass"', '-File"$dir\remote.ps1"', '$abc', '$def')
I have tested and the credential obj does authenticate successfully and creates a new PS process under the new user.
Problem
I cannot seem to figure out a way to launch a new powershell script file and pass in multiple arguments. I think I can't use ExecutionPolicy within an ArgumentList.
Expected result
What would be the correct method in order for me to run the final remote.ps1 script as the new user while also passing in multiple arguments? Thanks in advance.
Platform: Windows Server 2008 R2
Powershell: $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1