Can't run Start-Process with RunAsUser from .ps1 file

55 views Asked by At

Wrote a script that copies a .exe file to a folder then tries to run it as another user but the Powershel window just closes without running the .exe.

The command that runs it works fine if I run it on the terminal but not when I try to run the .ps1 file with Powershell (the window just closes after copying the file). The command also works (wether i run the .ps1 file or the command on the terminal) if i try to run it as the local user instead of another user.

if (Test-Path -Path "C:\Users\Gustavo\Desktop\Teste") {
    Remove-Item -Path "C:\Users\Gustavo\Desktop\Teste" -Recurse -Force | Out-Null
}

New-Item -Path "C:\Users\Gustavo\Desktop\" -Name "Teste" -ItemType "directory" | Out-Null
Start-BitsTransfer -Source "C:\Users\Gustavo\Downloads\MediaCreationTool22H2.exe" -Destination "C:\Users\Gustavo\Desktop\Teste\" -Description "Backup" -DisplayName "Backup"

Start-Process -FilePath C:\Users\Gustavo\Desktop\Teste\MediaCreationTool22H2.exe -Verb RunAsUser
0

There are 0 answers