Kill and restart the docker process:
$processes = Get-Process "*docker desktop*"
if ($processes.Count -gt 0)
{
$processes[0].Kill()
$processes[0].WaitForExit()
}
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"
In the if
clause I check if any running docker process has been found. There should never be more than 1 instance of "Docker Desktop" running so you can then kill the first one in the list.
To restart you need to know the full path of the "Docker Desktop.exe" file on your computer.