Read the script before it runs

Module 1: What AI already does in your job

Course outline

Quick check

Guess first, no penalty. An AI script should disable accounts nobody has used in 90 days. Its key line is $cutoff = (Get-Date).AddDays(90). It runs with no error. What happens?

PowerShell is the command language Windows admins use to make changes in bulk. Active Directory (AD) holds your company's user accounts. AI can write a script for both in seconds, and the script runs with your permissions.

One missing minus sign. No error, no warning. Monday morning, nobody can sign in.

Worked example

Before and after

The AI's script, then the safer version. Highlights show what changed.

AI script

$cutoff = (Get-Date).AddDays(90) Get-ADUser -Filter * -Properties LastLogonDate | Where-Object { $_.LastLogonDate -lt $cutoff } | Disable-ADAccount

Three changes:

  • The cutoff is 90 days in the past.
  • It only looks at enabled staff accounts in one OU (a folder of accounts), so admin and service accounts elsewhere are left alone.
  • -WhatIf "Displays a message that describes the effect of the command, instead of executing the command" (Microsoft Learn). You read the list before anything changes.

Fill the gaps

Fill the gaps in the dry-run version.

Script

$cutoff = (Get-Date).AddDays() Get-ADUser -Filter -Properties LastLogonDate | Where-Object { $_.LastLogonDate -and $_.LastLogonDate -lt $cutoff } | Disable-ADAccount

Show a finished AI help desk card
MY SETUP: Windows 11, Outlook and Teams, Cisco Secure Client VPN,
Microsoft 365 sign-in.
ASK AI: setup + what changed + what I tried + "list your assumptions".
BEFORE I SEND: version checked, vendor docs checked, no password
requests and no security steps for the user.
SCRIPTS: save the current state, -WhatIf, a batch of 10, log it.
INTERVIEW LINE: added in the next lesson.

Try it

Your steps, about 2 minutes

0 of 1
  1. 1.Add your script rule to your card: save the current state, -WhatIf first, then a batch of 10. Use it on one AI-written script for a routine task before you run anything.2 min

Practice

Question 1 of 3

You add -WhatIf to the end of Disable-ADAccount in a script and run it. What happens?

AI tutor

Ask about this lesson and get coached through the Try it task. The tutor is part of Learn Pro.

See Learn Pro