PowerShell - (Process|Service)

Windows Powershell Menu

About

OS - Process (Main Thread) / Program

Management

Verification

Write-Host "Checking docker daemon..."
If ((Get-Process | Select-String docker) -ne $null) {
    Write-Host "Docker is up and running"
}
Else {
    $Host.UI.WriteErrorLine("Please start the service")
    return
}

Get

one

  • After creation
$notepad = Start-Process notepad –PassThru
# Then
# $notepad | Stop-Process
  • Running
$oracle = Get-Process oracle
$oracle.StartTime
$oracle | Format-List *

list

Get-Process "oracle*"
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
   1034      86  3028912    3055532     324.39   3152   0 oracle

Stop

$notepad = Start-Process notepad –PassThru
$notepad | Stop-Process

Info

$notepad = Start-Process notepad –PassThru
# or 
$notepad = Get-Process notepad++
$notepad.StartTime
$notepad | Format-List *

Command on the path

if ((Get-Command $HUGO_EXE -ErrorAction SilentlyContinue) -eq $null) 
{ 
	Write-Warning "Unable to find $HUGO_EXE in your PATH"
	Write-Error "Unable to find $HUGO_EXE"
	exit(1)
} else {
	Write-Host "Hugo was found in your PATH"
	$HUGO_EXE_PATH=$HUGO_EXE
}

Exit Code

See Powershell - Exit

  • Adding the -PassThru will pass through a process object to the variable.
$process = Start-Process -FilePath $CMD_PATH -PassThru -NoNewWindow -Wait -ArgumentList "arg1","arg2"
if ($process.ExitCode -ne "0") {
# or $process.ExitCode -eq "0"
	Write-Error "An error occured during cmd. Exiting."
	exit(1)
} else {
	Write-Host ""
	Write-Host "No errors were reported but you may have somes, check the console output."
}







Share this page:
Follow us:
Task Runner