Use GitHub Copilot to Write Scripts Faster
What This Does
GitHub Copilot sits inside your code editor (VS Code) and suggests code as you type — or even generates entire functions from a comment describing what you want. For network admins writing PowerShell, Bash, Python, or Ansible, this cuts scripting time by 30-50% and helps you work confidently in languages you're less familiar with.
Before You Start
- Visual Studio Code installed (free — code.visualstudio.com)
- GitHub account (free account works)
- GitHub Copilot subscription ({{tool:GitHub Copilot.price}} individual — includes a free trial)
- The PowerShell extension for VS Code installed (search "PowerShell" in Extensions)
Steps
1. Install the GitHub Copilot extension in VS Code
- Open VS Code
- Click the Extensions icon in the left sidebar (looks like puzzle pieces) or press
Ctrl+Shift+X - Search for "GitHub Copilot"
- Click Install on the GitHub Copilot extension (published by GitHub)
- Restart VS Code if prompted
What you should see: A small Copilot icon appears in the VS Code status bar at the bottom of the window.
2. Sign in to GitHub
- Click the Accounts icon in the bottom-left corner of VS Code (looks like a person)
- Click Sign in with GitHub
- A browser window opens — log in to your GitHub account and authorize VS Code
- Return to VS Code — you're now signed in
What you should see: Your GitHub username appears in the status bar.
Troubleshooting: If Copilot shows "No subscription" after sign-in, go to github.com/copilot to start your trial or subscribe.
3. Write your first AI-assisted script
Open a new file in VS Code and save it with a .ps1 extension (for PowerShell). Then write a comment describing what the script should do:
# Get all Active Directory users in the IT department who haven't logged in for 60+ days
# Export results to CSV with: Name, SamAccountName, LastLogonDate, Department
# Email the CSV to helpdesk@company.com when complete
After typing the comment, press Tab to accept Copilot's suggestion, or wait a moment for it to appear as grayed-out text.
What you should see: Copilot suggests the first line of PowerShell code. Press Tab to accept it, then it suggests the next line. Continue accepting and refining.
4. Use the Copilot Chat panel for longer scripts
For more complex tasks, use Copilot Chat instead of inline suggestions:
- Press
Ctrl+Shift+Ito open the Copilot Chat panel - Type your request in plain English: "Write a PowerShell script that checks disk space on all servers in our domain and sends an alert email if any drive is over 85% full. Include a server list as a CSV input."
- Copilot writes the complete script in the chat panel
- Click Insert at Cursor to paste it into your file
What you should see: A complete, commented script in your editor ready to review.
5. Review and test before running
Always read through the generated script before running it — especially on production systems. Check:
- Is the logic correct?
- Are there any hardcoded values that should be variables?
- Does error handling cover your actual failure modes?
- Does the script do anything unexpected (deleting, modifying, or creating)?
Test on a non-production system or with a -WhatIf parameter first.
Real Example
Scenario: You need a PowerShell script to find all disabled AD accounts that still have Exchange mailboxes — a recurring cleanup task after employee offboarding.
What you type in VS Code:
# Find all disabled Active Directory users that still have Exchange Online mailboxes
# Output a CSV with: Name, SamAccountName, Email, DisabledDate
# This will be run monthly for license cleanup
What Copilot generates: A working PowerShell script using Get-ADUser and Get-Mailbox cmdlets, with filtering logic, error handling, and CSV export. You review, adjust the output path and any environment-specific settings, and run it.
Time comparison: Writing this script manually: 45-75 minutes. With Copilot: 5-10 minutes of review and adjustment.
Tips
- Write clear, specific comments — the more context you give, the better the suggestion. "Get all users" is worse than "Get all AD users where Enabled=False and PasswordLastSet > 90 days ago"
- Ask Copilot to "explain this script" in the Chat panel if you inherited code you don't understand
- Use Copilot in languages you're learning (Python, Terraform, Ansible) — it teaches syntax by example as you work
Tool interfaces change — if a button has moved, look for similar AI/magic/smart options in the same menu area.