Use this script to check on-premises Active Directory to determine if an account is enabled and display it in a formatted column. In summary, the script reads a list of user-names from a text file, retrieves their Active Directory user information, and displays their names and enabled status in a formatted table.
Technical Details
This PowerShell script performs the following actions:
1. It reads the contents of a text file named “migrate_user.txt” located at “C:\temp” and assigns the content to the variable $User.
2. It iterates over each item in the $User variable using a foreach loop, assigning each item to the variable $UItem.
3. Within the loop, it executes the cmdlet Get-ADUser to retrieve Active Directory user information for the user specified by $UItem.
-
- The -Property Enabled parameter specifies that the “Enabled” property should be included in the output.
4. The output of Get-ADUser is then piped (|) to the Format-Table (alias FT) cmdlet, which formats the output as a table.
-
- The Name and Enabled properties of each user are displayed in the table.
- The -Autosize parameter adjusts the column widths automatically based on the content.
Get the Script
Copy and paste from below or download the txt version here.
$User = Get-Content "c:\temp\migrate_user.txt"ForEach ($UItem in $User){
Get-ADUser $UItem -Property Enabled | FT Name, Enabled -Autosize
}
********************
The list containing users should be formatted as: (using user IDs pulled from AD)
Ctest1
Ctest2
User1
Stest3
Save it as a CR/LF text file.