Help script disable user on AD

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 years, 6 months ago.

  • Author
  • #11989
    Profile photo of Abacaxi Andrade
    Abacaxi Andrade

    Good night guys!
    Need a little help!
    I made a script to disable users in the ad but I need to make an if and else to take the test within a file .csv whether or not hesitate in AD and disable.

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    Import-Module ActiveDirectory
    $UsersToDisbableList=IMPORT-CSV C:\users.csv  
    Get-Credential -Credential avista\adm
    Connect-QADService -service $PrimaryDC 
    Function DisableUsers 
            [string] $_SamAccountName
    Get-ADUser -filter { DisplayName -eq $_SamAccountName } | Set-ADUser -Enabled $false
    write-host ("Usuario: $_SamAccountName [Inactive]")
    Start-Sleep -s 2 
    FOREACH ($User in $UsersToDisbableList) { 
        DisableUsers $User.SamAccountName
  • #11993
    Profile photo of Don Jones
    Don Jones

    I'm sorry – I don't think I understand what you're asking for.

    Are you saying you need it to take a CSV file as input? What does the CSV file look like?

    Are you saying you want to check and see if the user exists first? What do you want it to do if the user does not exist?

You must be logged in to reply to this topic.