Get Account Expiry Date for the list of users - Powershell

Get Account Expiry Date for the list of users - Powershell 


The standard approach lets you to get the account expiry details for the entire ADuser and its also time consuming. Since it has to return the all the users with their expiry details.
Querying such a large database takes lot of time.

Below script will allow you to narrow down your search query.

Script:

#import AD module
Import-Module ActiveDirectory;

#save the list of users in text file at any given location, mention that path below
$userlist = Get-Content "C:\folder\listofuser.txt";

# $output variable will save the result in it
$Output = foreach($user in $userlist)
{

#Querying each user and returning their respective details by using Select

Get-ADUser -property * -ldapfilter "(samaccountname=$user)"| select sAMAccountName, Displayname,accountExpirationDate, Enabled, 
Title  

};

#Mention the filename and path below to save the output
$Output| Export-csv -path "c:\folder\result.csv"

How to Use:

1. Open notepad, copy all the users that you want to query for account expiration date.
2. Mention that path in the script
3. Mention the path for result of the script to return
4. Execute


Thanks guys, 
Please comment down below if you have any query.
Have Nice day!




Comments

Popular posts from this blog

How to check Remote Server Configuration/Info - Using Powershell

How To Move or Migrate SQL Server Workload to Azure SQL Database

Check Server Info - Powershell