Automation with PowerShell: remoting, testing and scheduling
You build reliable automation across many servers with remoting over SSH, parallel runs, Pester tests, classes and secret management.
Level 301 · 16 lessons · 18 practice labs
Lessons
Remote work
- PowerShell remoting over SSH
- Running commands on many servers with Invoke-Command
- ForEach-Object -Parallel and background jobs
- Short task: disk and service checks on five Linux servers
Testing and quality
- Unit testing with Pester
- Mocking and integration testing in Pester
- Code review with PSScriptAnalyzer
- Short task: add tests to your module and run them in CI
Design
- Classes and enums
- Configuration data: psd1, JSON and per-environment settings
- Secrets with SecretManagement
- Automating with REST APIs: paging, retries, authentication
- Short task: sync a user list from an API with local accounts
Scheduling and operations
- Running a pwsh script with a systemd timer
- Leaving a trail with transcripts and script logging
- Capstone: automation that finds and fixes configuration drift on ten servers
Practice labs
- Open a remote PowerShell session over SSH: Open an SSH-based remote session to the target server and submit its uptime.
- Run disk and service checks on five servers: Use Invoke-Command to gather disk fullness and one service's state from five servers and combine them in one table.
- Throttle parallel checks and report unreachable hosts: Run checks with ForEach-Object -Parallel under a throttle limit and list hosts that time out separately.
- Write a first Pester test for a function: Write a Pester test covering three cases of a function that evaluates a disk threshold and show it passes.
- Mock a remote call: Test a function that calls Invoke-Command with Mock, without reaching a real server, and assert the call count.
- Fix PSScriptAnalyzer findings and gate on them: Fix the analyser warnings in the module and write a script that runs tests and the analyser together and stops on failure.
- Load settings per environment: Move test and production settings into separate data files and make the script load the right one by parameter.
- Move a clear-text password into a vault: Move an API key embedded in a script into a SecretManagement vault and update the script to read it from there.
- Find and fix configuration drift across servers: Compare the SSH config on the target servers with the baseline, fix those that drift and produce a change report per server.
- Turn an API response into typed objects: Convert the server list from the lab API into custom objects with correctly typed date and number fields and submit the oldest record.
- Fetch all records from a paged API with retries: Write a function that fetches every user from a paged, occasionally failing API with retries and back-off.
- Sync an API user list with local accounts: Compare the API list with local accounts, create the missing, lock the extra and report what was done.
- Pin status values with an enum: Replace the free-text status strings in check results with an enum holding Ok, Warning and Critical, and show that an invalid value is refused.
- Write a class with a method for a server record: Write a class holding name, role and last check time; its constructor refuses an empty name, a method returns how many days ago the check ran, and the objects are built from a CSV.
- Model check results with a class and enum: Turn string status fields into an enum and results into a class, and show an invalid status is rejected.
- Run a pwsh script with a systemd timer: Write service and timer units that run the inventory script nightly and verify the next run time.
- Add a transcript trail to a scheduled script: Add a dated transcript and a non-zero exit code on failure to the script, removing transcripts after thirty days.
- Catch a scheduled script that silently stops: Add a lock against a second copy and a last-success stamp to the timer-driven script; set up a check that writes an alert file when the unit fails or the stamp is over a day old, and test it by triggering a failure on purpose.
About this course
You build reliable automation across many servers with remoting over SSH, parallel runs, Pester tests, classes and secret management.
What you will learn
- Remote work
- Testing and quality
- Design
- Scheduling and operations
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.