Script required to disable multiple users on specific date and time

alok singh 1 Reputation point
2021-10-07T05:00:41.807+00:00

I Need a powershell script which can disable multiple user on particular specified different different date and time on CSV file. Also i need CSV format for this requirement.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,190 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Gary Reynolds 9,406 Reputation points
    2021-10-07T07:52:22.237+00:00

    Hi @alok singh

    It's not possible to schedule users to be disabled at a specified time, however, you could set the user account to expire at a specified time which will prevent the user from logging on.

    Import-Csv .\userList.csv | ForEach {  
      
        Set-ADAccountExpiration -Identity $_.Username $_.time -WhatIf  
      
    }  
    

    something like this should do the job.

    Gary.


  2. Gary Reynolds 9,406 Reputation points
    2021-10-11T06:25:15.257+00:00

    Hi @alok singh

    What cloud identity provider are you using?

    For Azure AD connect you could change to a PTA based configuration, which Ibelieve this will honour the account expiry.

    Gary.

    0 comments No comments