Help script disable user on AD

Welcome Forums General PowerShell Q&A Help script disable user on AD

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
5 years ago.

  • Author
    Posts
  • #11989

    Participant
    Points: 0
    Rank: Member

    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 
    { 
        Param( 
            [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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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?

The topic ‘Help script disable user on AD’ is closed to new replies.