An operations team needs a reusable PowerShell toolkit that audits disk usage, logs findings, and surfaces actionable alerts. Building on Lab 1, you will apply Copilot fundamentals to produce production-ready scripts that downstream labs (Python, YAML, and Ansible) will consume.
- Prompt Copilot to scaffold and refactor scripts.
- Implement defensive error handling and structured logging.
- Package scripts into reusable modules and translate outputs for downstream tooling.
- PowerShell 7+.
- VS Code with PowerShell & Copilot extensions.
- Test machine or container with mock drives.
- Create a new file named
DiskAudit.ps1inside theLab1_PowerShellfolder.
Inline Copilot (start typing a comment and let Copilot suggest the change).
- Copy the following Comment and paste in the script file:
#Generate a PowerShell script that lists disks, free space %, and flags volumes below 15% free.
-
Pause typing and observe Copilot's ghost text suggestion; accept with Tab if appropriate
-
From the toolbar select Run - Run without debugging or (F5) to Run the script
-
Use GitHub Copilot to refactor the script to change the free space threshold from 15% to 20%.:
-
Open Copilot Chat (Ctrl+I) and ask:
Change the free space to 20%
- The goal is to learn how Copilot can help you refactor your script using inline suggestions.
Use Edit mode - Open Copilot chat Ctrl+shift+i
Make sure in are in Edit mode and stand on the script file DiskAudit.ps1
-Ask Copilot to:
Add ComputerName parameter to the PowerShell script and use it for remote execution
wrap the script in `Try/Catch` blocks.
- Open script file script.ps1 Do you know what this script does?
- Change copilot mode to ask mode -make sure your context is the script file
- Ask Copilot:
Explain in plain English what this PowerShell script does?
- Run the script and check if you see files in the SystemReport folder.
- Change to Agent mode
- Ask Copilot Agent:
Add detailed comments to this script.
Refactor and optimize this script.
- Review the changes and keep them.
- Make sure the script is running.
- Ask Copilot to help you persist results as JSON
persist all results from csv files to one JSON file
- Run the script and check if you see a json files with all the details in the SystemReport folder.
🔥Lab 1 is complete! Proceed to Lab 2 – Python Automation with Copilot.


