Code below will run an application and PowerShell will also close it after a few seconds. $process_id = Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{ CommandLine = 'cmd /c "C:\dev\remind.bat"' } | Select-Object processid | ft -HideTableHeaders | Out-String Start-Sleep -Seconds 2.5 stop-process $process_id Sample contents of remind.bat: @echo off echo "Shutdown the server. Do it now." Notepad ================== Notepad is on the batch file so the command window will stay on the top of any running applications. Sample output of the above code: Code below will run calculator and close after a few seconds specified on the code: Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{ CommandLine = 'calc.exe' } | Select-Object processid | ft -HideTableHeaders | Out-String Start-Sleep -Seconds 2.5 $get_process_id = Get-Process ...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.