02 / PROCESS CONTROL AND REMOTING · LESSON 05

Preview and stop simulated processes

Use WhatIf to preview one process stop and apply a separate, precisely targeted simulated change.

12 min · learn at your pace

A stateful lab you can inspect

Stop-LabProcess changes only the virtual fleet-state.json file. Get-LabProcess then returns the remaining running entries. The state survives subsequent Run operations and completed workspace saves. Check starts again with the original fixtures, so exploratory process changes do not contaminate assessment.

The command supports -WhatIf. It describes the intended action while leaving state untouched. -Confirm:$false suppresses an interactive confirmation prompt for the explicit change in this exercise. A preview is not approval for every later change: identify the exact computer and PID each time.

Duplicate names deserve care

app01 has two lab-worker instances, and db01 has processes with the same PIDs. Preview app01/410, then stop app01/420. The first remains running; the second disappears from the running list. The database host remains unchanged.

The simulation rejects protected processes and denied actions. Repeating a stop on an already stopped known entry is a no-op. An unknown PID throws. These are teaching-module rules, not a complete emulation of Stop-Process on every operating system.

Transfer the idea carefully

In a local environment, Get-Process and Stop-Process act on actual processes and access rights. A name-based stop can affect several instances. Review identity and consequences before using those commands. This browser exercise never invokes them; the next lesson builds a wrapper that checks the reviewed process start time and puts its mutation behind ShouldProcess.

Go deeper

Read the official reference.

Try an example.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
Get-LabProcess app01 | Select-Object Id,ProcessName
Stop-LabProcess app01 -Id 410 -WhatIf
YOUR TURN

Put it into practice.

Import the lab module. Preview stopping app01 PID 410 with WhatIf, then stop app01 PID 420 with confirmation suppressed. Emit the remaining app01 processes with ComputerName, Id, and ProcessName. Leave db01 and all other process entries unchanged.

See an explained solution
One way to solve it.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
Stop-LabProcess -ComputerName app01 -Id 410 -WhatIf
Stop-LabProcess -ComputerName app01 -Id 420 -Confirm:$false
Get-LabProcess app01 | Select-Object ComputerName,Id,ProcessName

The preview emits no success-pipeline object and preserves PID 410. Only PID 420 changes state; subsequent queries reveal that precise change.