Bird
0
0

This script is intended to disable users listed in 'disable.csv':

medium📝 Debug Q7 of 15
PowerShell - Active Directory
This script is intended to disable users listed in 'disable.csv':
Import-Csv disable.csv | ForEach-Object {
Disable-ADAccount -Identity $_.UserName
}

It fails with 'Cannot find an object with identity'. What is the likely fix?
AUse Get-Content instead of Import-Csv
BReplace Disable-ADAccount with Remove-ADUser
CAdd -Confirm:$false to Disable-ADAccount
DCheck that the CSV column is named 'UserName' exactly
Step-by-Step Solution
Solution:
  1. Step 1: Verify CSV column names match script property access

    If the CSV column is not exactly 'UserName', $_.UserName will be null causing identity not found.
  2. Step 2: Understand error cause

    Incorrect property name means Disable-ADAccount receives empty identity, causing failure.
  3. Final Answer:

    Check that the CSV column is named 'UserName' exactly -> Option D
  4. Quick Check:

    Property name mismatch causes identity errors [OK]
Quick Trick: Match CSV headers exactly to property names in script [OK]
Common Mistakes:
  • Changing cmdlet instead of fixing property names
  • Using Get-Content which does not create objects
  • Adding unnecessary parameters without fixing root cause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes