Using PSU to run a local .bat file on my PC

Product: PowerShell Universal
Version: 5.2.1

So im trying to create an powershell automation to run my batfile for my game server. but it seems like the ps universal is not running the bat file for some reason.
I already tested the path everything is also working if I use it on my local powershell

$ServerPath = “$Secret:ServerPath”
$pathObject = [System.IO.Path]::GetFullPath($ServerPath)

if (Get-Process -Name WindowsTerminal -ErrorAction SilentlyContinue) {
Write-Host “Server is already running!”
Write-Host “Use the Stop Server Script to Restart”
} else {
Write-Host “Server is starting!”
Start-Process -FilePath $pathObject -Wait
Write-Host “Please Wait!..”
}

Can you try running the bat file directly so the STDOUT gets redirected?

$ServerPath = “$Secret:ServerPath”
$pathObject = [System.IO.Path]::GetFullPath($ServerPath)

if (Get-Process -Name WindowsTerminal -ErrorAction SilentlyContinue) {
Write-Host “Server is already running!”
Write-Host “Use the Stop Server Script to Restart”
} else {
Write-Host “Server is starting!”
& $pathObject 
Write-Host “Please Wait!..”
}

Hi adam

Thanks for replying. Im not really sure what do you mean by that. so here’s what is going on. the when you open the bat file it serves as a console for the server thats why i need it to be opened.

The script i posted is opening the bat file and leaving it open as it completes. I want to mimic that result aswell with PSU.

I was just suggesting running the bat file with the call operator (&) to see if you could capture the output of the bat file. Start-Process won’t do that automatically.

This is mostly just to see what the error from the bat file might be. Do you get any feedback from PSU when trying to run it (e.g. errors\warnings)?