Read the script before it runs

Módulo 1: What AI already does in your job

Conteúdo do curso

Esta aula ainda não está no seu idioma, então aqui está em inglês.

Teste rápido

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

Antes e depois

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.

Preencha as lacunas

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

Seus passos, cerca de 2 minutos

0 de 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

Exercícios

Pergunta 1 de 3

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

Tutor de IA

Tire dúvidas sobre esta aula e tenha ajuda na tarefa do “Experimente”. O tutor faz parte do Learn Pro.

Ver o Learn Pro