Files
AIGame/AIServer/deploy/windows/Stop-Server.ps1
T

16 lines
835 B
PowerShell

[CmdletBinding(SupportsShouldProcess)]
param([string]$TaskName = 'AIGame-AIServer', [switch]$UninstallTask)
$ErrorActionPreference = 'Stop'
$expected = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot 'aiserver.exe'))
if ($PSCmdlet.ShouldProcess($expected, 'Stop this release and its startup task')) {
$task = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
if ($task) {
Stop-ScheduledTask -TaskName $TaskName
if ($UninstallTask) { Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false }
}
Get-CimInstance Win32_Process -Filter "Name='aiserver.exe'" | Where-Object {
$_.ExecutablePath -and [IO.Path]::GetFullPath($_.ExecutablePath) -eq $expected
} | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
Write-Output 'Stopped. Database and logs preserved.'
}