Remoting and Automation

Harry · 13 Sep 2026 · 1 views

PowerShell Remoting

PSRemoting runs commands on remote machines using WinRM:

Invoke-Command -ComputerName srv01 -ScriptBlock { Get-Service Spooler }
Invoke-Command -ComputerName srv01,srv02 -ScriptBlock { Get-Process -Name winlogon }

Enable it on targets with Enable-PSRemoting -Force from an admin shell.

Run Jobs in Background

Start-Job -ScriptBlock { 1..10 | ForEach-Object { $_ } }
Get-Job
Receive-Job

Jobs keep output and run independently of the console.

Scheduled Tasks

Register-ScheduledTask ties scripts to schedules:

$action = New-ScheduledTaskAction -Execute 'pwsh' -Argument '-File C:scriptsackup.ps1'
Register-ScheduledTask 'Nightly Backup' -Action $action -Trigger New-ScheduledTaskTrigger -Daily -At 2am

Secrets and Safety

  • Never embed passwords; use Secret Management or prompts.
  • Validate inputs and use -ErrorAction Stop.
  • Log outputs and run tasks under service accounts.
  • Test scripts in a VM before production.

Key Points

  • Invoke-Command runs across machines.
  • Start-Job parallelizes long work.
  • Register-ScheduledTask automates on a schedule.
  • Secrets, logging and tests keep automation safe.

From command to script

Share this post:

Comments (0)

Please login or register to comment.