I've been writing a ps menu script to help me with a gaming server.
One of the functions is a loop, checking if a process is running, and grabs some data from files. However Ive been trying to break the loop to go back to main menu, at the moment we have to close the script and re-open it.
Here's what Ive been trying from some examples I've found online
# Guardian Mode, keeps halo online running
Function guardian {
while ($true) {
cls
if ((Get-Process -Name eldorado -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host -ForegroundColor Red "Server Is Not Running" ;
.\eldorado.exe -launcher -dedicated -headless -window -height 300 -width 300 ;
"Guardian Started Headless Eldorito Server $($date)" | Add-Content .\dedicatedServer.log
}
if ([console]::KeyAvailable)
{
echo "Press space to go back to mainmenu";
$x = [System.Console]::ReadKey()
switch ( $x.key)
{
F12 { $continue = mainmenu }
}
}
else {write-host -ForegroundColor Green "Guardian Mode is Activated, Server Is Running (Checking 15s)"
Write-Host -ForegroundColor cyan "Name" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).Name
Write-Host -ForegroundColor cyan "Player Count:" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).numPlayers
Write-Host -ForegroundColor cyan "Variant" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).variant
Write-Host -ForegroundColor cyan "Map" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).map
Write-Host -ForegroundColor cyan "GameType" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).variantType
Write-Host -ForegroundColor cyan "Status" ; (Invoke-WebRequest -Uri 127.0.0.1:11775 | ConvertFrom-Json).status
Get-Content .\chat.log -Tail 5
Write-Host -ForegroundColor cyan "Running Since" ; Get-Content .\dedicatedServer.log -Tail 1
}
Start-Sleep -Seconds 15
}
}