AI writes PowerShell and Bash faster than you ever will — and a peer-reviewed study found exploitable vulnerabilities in 100% of the AI-generated admin scripts it examined. Both facts are true at once. This module teaches the resolution: the mandatory safety review, dry-run discipline, and execution boundaries that let you keep the speed without inheriting the flaws.
Kavitha is a sysadmin at a Hyderabad GCC — nine years in, AD, Entra, Intune, comfortable in PowerShell but never with time to write it. On a Wednesday afternoon HR hands her a list of 43 leavers from a divested business unit, due for offboarding by Friday. She does what any of us would do in 2026: asks her AI assistant for a bulk-offboarding script. Thirty seconds later she has 60 clean-looking lines: disable accounts, revoke sessions, remove group memberships, set out-of-office, move to the disabled OU. It reads well. It would have run.
Because her team had adopted the review protocol this module teaches, she ran the checklist instead of the script. Finding one: the disable step filtered on department -eq "Logistics" — the department, not the CSV list. Nineteen Logistics employees who were staying would have been disabled with the 43 leavers, including two service accounts that run the warehouse integration. Finding two: the script authenticated with a plaintext app secret pasted into line 4 — which the model had helpfully invented as a placeholder, and which the intern who reused the script next quarter would have replaced with a real one. Twenty minutes of review, two findings, either of which would have made Friday memorable.
Neither finding means the AI is bad at PowerShell. The script's logic was 90% right and the 30 seconds saved her an hour. The point is harsher and more useful: AI-generated admin scripts are competent-looking by construction and safe only by verification. In this module, the review protocol is not a suggestion attached to the skill. It is the skill.
This module's rule is built on the strongest single finding in this track's research base. A Dakota State (Beacom College) study examined automation scripts generated by ChatGPT, Copilot and Gemini for common admin tasks, and found that every script studied — 100% — contained exploitable vulnerabilities, running 13–14 findings per platform across 17 vulnerability classes: hardcoded credentials, missing input validation, unscoped operations, absent error handling, injection-prone string construction, over-broad permissions.
Sit with what that number means operationally. It does not mean AI scripts are unusable — the same scripts were mostly functionally correct, which is exactly what makes them dangerous: they work in the demo, so they ship. It means that generation and hardening are two different jobs, the model does the first, and nobody is doing the second unless you are. A support engineer who can run the hardening pass on AI output is worth more than one who can write the script from scratch slowly — and measurably more than one who runs AI output raw.
The study's number to carry with you is not "13–14 findings per platform." It is 100%. Not most scripts, not scripts from the weaker model — every script, from every platform studied. The review is not for the occasional bad draft; it is for all of them.
Every AI-generated script that touches real systems runs this checklist before execution. No exceptions for "small" scripts — Kavitha's was 60 lines.
-WhatIf first, alwaysthe script must support and be first executed in dry-run mode (-WhatIf in PowerShell, --dry-run or an echo-only pass in Bash). If the AI didn't build the dry-run path, that is your first change request to it.Get-ADUser -Filter feeding a Disable- or Remove- verb is guilty until proven scoped.password, secret, key, token before anything else.Then — and only then — the graduation sequence: dry-run against production data and read every line of the output; live run against a test scope (one OU, five accounts); full run with logging on. Kavitha's Friday deadline survived all three stages with hours to spare, which is the quiet argument for the protocol: it is faster than the incident.
The most dangerous scripts are the ones generated for one-time use under deadline — exactly Kavitha's situation. "It only runs once" is not a reason to skip review; it is the reason there will be no second chance to catch the flaw.
Every desk has them: the 400-line script the last admin left, running nightly, undocumented, load-bearing. AI has made reading them cheap. Paste the script (sanitized of any embedded secrets — and finding those is itself finding one) and ask for three artifacts:
Then verify the explanation the only way that counts — in a sandbox VM or test tenant, watching what the script actually does against what the AI said it does. The explanation is a hypothesis about the code; the sandbox is the check. Lab 6 hands you a 300-line legacy script with two planted dangers — an unscoped Remove- operation and a plaintext credential — and the artifact is a risk report that names both.
Bulk changes to AD, Entra or M365 are where one bad script destroys a tenant, so bulk work carries three non-negotiable conventions beyond the standard review:
Run the AI's group-restructure script directly. A malformed CSV row maps 200 users to a nonexistent group; the loop logs errors silently and continues. Discovery comes via help-desk flood Monday morning; reconstruction takes two days because nobody recorded prior state.
Validation rejects the malformed rows with line numbers. Dry-run output shows one user losing all access — investigated, corrected. Rollback file written. Execution logged, 100% success count verified against console. Total overhead: forty minutes.
Terminal copilots — Microsoft AI Shell, Warp-class terminals, Claude Code and its peers — move AI from "drafts scripts elsewhere" to "sits inside your session, suggesting and sometimes executing commands." That is genuinely useful for command recall and error remediation, and it collapses the review gap to zero unless you rebuild it deliberately: when suggestion and execution live one keystroke apart, the checklist must become a written execution policy — decided in daylight, not at the prompt.
| Class | Rule | Examples |
|---|---|---|
| Read-only queries | AI may run without approval | Get-*, ls, status checks, log reads |
| Reversible single-object changes | AI suggests; human executes | restart a service, clear a cache, re-register an app |
| Bulk or multi-object changes | Script path only — full review protocol | anything iterating over users, devices, groups |
| Destructive or identity-touching | AI drafts only; never executes; named-human runs after review | Remove-*, permission grants, credential operations |
Write it, share it with the team, and treat a violation as a process failure even when nothing broke. The boundary's value is that it exists before the 2 a.m. incident where "just let the AI fix it" feels reasonable.
Client-account rules apply to scripts exactly as to tickets: a script containing client hostnames, tenant IDs or account structure is client data. Approved endpoints or local models for generation and explanation, placeholders for real identifiers in prompts, substitution done locally.
Three more surfaces complete the safety-first toolkit:
Scheduled-automation documentation and smoke tests. Silent failure of a scheduled job is a classic outage precursor — the cleanup task that stopped running in March is why the disk filled in July. AI-generate two artifacts for every scheduled job and RMM automation you own: documentation (what it does, what it touches, what depends on it, who owns it) and a smoke test — a lightweight check that the job ran and produced its expected effect, wired to alert someone when it did not. An afternoon of AI-assisted work converts a folder of mystery jobs into a monitored, documented estate.
Self-service remediations. Proven fixes — clear the cache, re-register the app, reset the VPN adapter — packaged as one-click user-runnable tools or Intune proactive remediations / RMM-pushed scripts. AI drafts the remediation; you harden it with the full protocol plus the self-service extras: it must be safe when run twice, safe on the wrong machine, and silent-failure-proof, because no engineer is watching when it runs. Done well, these are the most honest deflection there is — the user's problem is actually fixed, not deflected into a chatbot loop. Module 7 will insist you count them that way.
Report automation against console truth. AI writes the Graph-API and RMM-API reporting scripts for asset, license and patch-compliance reports in minutes. The habit that keeps them from becoming confidently-wrong PDFs: before any report leaves you, verify a sample of its numbers against the admin console directly. A reporting script with a subtly wrong filter — counting all devices where it should count active ones — produces plausible numbers forever, and plausible-but-wrong compliance figures surface at the worst possible moment: during an audit. Spot-check three numbers, every report, every time.
The study says 100% of AI-generated admin scripts carried vulnerabilities; your experience says AI scripting saves hours a week. Both stay true, and the review protocol is what lets you live with both: generate fast, review always, dry-run first, scope every filter, hardcode nothing, and let PSScriptAnalyzer read what you skimmed. The engineer who does the hardening pass is the one who gets the speed for free.