$Adminusername = 'domain\blah'
$password = 'blah'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Adminusername, $securePassword
$path = "\\blah\script.ps1"
Start-Process powershell -ArgumentList "-noexit", "-file $path", "-command &{Set-ExecutionPolicy Bypass}", "-username $username", "-roamingprofilepath $RoamingProfilePath", "-localappdatapath $localappdatapath" -credential $Credential
The above script is a PowerShell process that starts a 2nd PowerShell, but running it as a different user. The arguments from the first PowerShell session are passed into the second one.
It works fine, except that in the 2nd PowerShell process, execution policy doesn't bypass and it will keep prompting you to allow the script to run. What am I doing wrong here?