If I use powershell to run an external command, how do I obtain it's pid?
I'd like to obtain it for purposes of gracefully exiting it later (not just straight up killing the process, but rather doing it in more the sense of a finally
block)
Using System.Diagnostics.Process object, you can start a process, and return a Process object, which includes the newly created process PID.
For example:
$Process = [Diagnostics.Process]::Start("nssm.exe")
Write-Host $Process.Id