For IT Support Technician / Help Desk Analysts ·
What you'll accomplish
By the end of this guide, you'll be generating working PowerShell scripts for AD administration, M365 management, and system reporting tasks — even if you're not a confident scripter. You'll write your first complete script, test it safely, and have a library of prompt patterns for the most common IT automation tasks.
What you'll need
$PSVersionTable.PSVersion)Import-Module ActiveDirectory)Getting a working script from ChatGPT requires specificity. The formula:
[What it does] + [Input source] + [Output format] + [Error handling] + [Environment specifics]
Weak request: "Script to disable inactive AD accounts"
Strong request: "Write a PowerShell script that finds AD user accounts that haven't logged in for 90+ days, using LastLogonDate attribute. Input: no manual input needed — query all users. Output: first export a CSV preview (Name, SamAccountName, LastLogonDate, OU), then in a second step disable only after manual review. Error handling: if AD module missing, show clear error message. Environment: on-premises AD, Windows Server 2019."
Go to chat.openai.com. In a new conversation, type your script request using the formula above. Start with something low-risk for your first test.
Good first script to request: Generate an AD user report (read-only — no changes to the system)
Write a PowerShell script that exports a report of all Active Directory users to a CSV file. Include columns: DisplayName, SamAccountName, EmailAddress, Department, Manager, Title, Enabled (yes/no), LastLogonDate. Export to C:\Reports\AD-Users-[date].csv where [date] is today's date in YYYYMMDD format. Include error handling if the AD module isn't available.
What you should see: A complete script with Get-ADUser, proper property selection, the calculated date field for the filename, and a try/catch block for error handling. It will also include comments explaining what each section does.
Before running ANY generated script:
C:\Reports\ — does this directory exist?)For read-only/export scripts: risk is low. Run directly.
For scripts that modify AD/systems: ALWAYS use -WhatIf first.
Open PowerShell as Administrator. Set execution policy if needed:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
For a read-only script, run it directly:
& "C:\Scripts\ad-user-report.ps1"
For a modifying script, test first:
# Add -WhatIf to the risky commands within the script before running
# Example: Disable-ADAccount -Identity $user.SamAccountName -WhatIf
What you should see: Either a successful run producing your output (CSV file, console output), or an error message.
If the script errors out, copy the entire error message (including the line number and error type) and paste it back into the ChatGPT conversation:
"This script failed with this error: [paste full error message]. Here's the script: [paste the script]. What's wrong and how do I fix it?"
What you should see: ChatGPT identifies the error (usually a typo, missing module, or environment difference) and provides a corrected version.
AD user report:
Write a PowerShell script to export all AD users with properties: [list properties]. Filter: [any filter — enabled only, specific OU, etc.]. Output: CSV to [path].
Bulk AD account modification:
Write a PowerShell script that reads a CSV with columns [list] and for each row [what to change] in Active Directory. Use -WhatIf mode by default; comment out WhatIf when ready to run for real.
M365 license report:
Write a PowerShell script using the ExchangeOnlineManagement module to generate a report of [what: all licensed users / users with specific license SKU / unlicensed users]. Output to CSV.
Software inventory check:
Write a PowerShell script that checks if [software name] is installed on remote computers in a given list of hostnames. Output: CSV with hostname, installed (yes/no), version if installed.
Scheduled task creation:
Write a PowerShell script that creates a scheduled task to [what] running at [when] under [system/specific user context]. Include error checking.