none
For Each IF Else - Help RRS feed

  • Question

  • Hi

    I've made a PS Script to import a CSV list of users, read the list and then update an AD Attribute. What I want to now do is capture any that get skipped (because the attribute does not need updating) or fail.

    Here's what I already have:

    $Logfile = 'C:\Users\XX\Documents\disabledusers.log'
     
    Start-Transcript -Path $Logfile
    
    Import-Module ActiveDirectory
    
    $USERS = Import-CSV C:\Users\XX\Documents\userstoupdate.csv
    
    $USERS|Foreach{
    Set-ADUSer -Identity $_.samaccountname -Enabled $False
    Write-Host "Successfully disabled account $($_.SamAccountName)"
    }
     
    Stop-Transcript

    Tuesday, June 11, 2019 9:19 AM

All replies