Protego field desk
Operations and Security · Admin automation

L8. Remoting, Jobs, and Scheduled Automation

Course outlineLesson 8 of 10
PowerShell Zero to Hero: course overview

Run work beyond your local shell with PowerShell remoting, background jobs, ForEach-Object -Parallel, scheduled tasks, and safe fan-out patterns.

Remoting Concepts

PowerShell remoting lets you run commands on other machines. On Windows, WinRM is common. PowerShell 7 also supports SSH-based remoting, which is useful across platforms. The ComputerName examples below use WSMan/WinRM and require a configured Windows endpoint plus authorization. SSH remoting requires PowerShell and SSH on both hosts, with the PowerShell SSH subsystem configured on the target.

Enter-PSSession -ComputerName server01
Invoke-Command -ComputerName server01 -ScriptBlock { Get-Service }

In real environments, remoting depends on network reachability, authentication, authorization, host configuration, and logging. Do not treat it as just a command syntax problem.

For an SSH endpoint, use Enter-PSSession -HostName server01 -UserName operator instead of ComputerName. Use an authorized lab host and verify its SSH host key.

Jobs

Jobs let work continue in the background:

$job = Start-Job -ScriptBlock { Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 }
Receive-Job $job -Wait -AutoRemoveJob

PowerShell 7 also supports parallel processing:

1..5 | ForEach-Object -Parallel {
  "Worker $_ on $([Environment]::MachineName)"
} -ThrottleLimit 3

Use throttling. Unlimited parallelism can overwhelm endpoints, APIs, or your own machine.

Scheduled Automation

On Windows with the ScheduledTasks module and PowerShell 7 installed, scheduled tasks are practical. Create the script path below first, then choose a task identity with the permissions the script actually needs:

$pwsh = (Get-Command pwsh -ErrorAction Stop).Source
$action = New-ScheduledTaskAction -Execute $pwsh -Argument '-NoProfile -NonInteractive -File C:\Scripts\Inventory.ps1' -WorkingDirectory 'C:\Scripts'
$trigger = New-ScheduledTaskTrigger -Daily -At 3am
Register-ScheduledTask -TaskName 'DailyInventory' -Action $action -Trigger $trigger

Inspect the registered task and its run history. Test under its configured identity: interactive sign-in, network credentials, and mapped drives may be unavailable to that identity.

In cloud and DevOps environments, the same script may run under GitHub Actions, Azure Automation, or another runner. Keep scripts non-interactive, parameterized, logged, and idempotent.

Lab

  1. Start a local job that gathers process data.
  2. Receive the result and remove the job.
  3. Use ForEach-Object -Parallel with a throttle limit.
  4. Draft a scheduled-task command for a daily inventory script.

References

Continue Learning

Next, review PowerShell security and logging.

Exam Focus Points
  • ✓PowerShell remoting can use WinRM or SSH depending on platform and configuration
  • ✓Invoke-Command runs commands remotely; Enter-PSSession opens an interactive session
  • ✓Start-Job runs background work and Receive-Job collects results
  • ✓Use ThrottleLimit to avoid overwhelming systems during parallel execution
  • ✓Scheduled automation should be non-interactive, parameterized, logged, and idempotent
Knowledge Check

1. Which command collects output from a background job?

2. Why is throttling important in parallel automation?