Use this script for Migrations and on-premises Active Directory maintenance. Check a user account, as read from a list of accounts, for several attribute properties. These attributes are usually checked during a migration to a cloud provider, but they can be substituted for any attribute you choose.

Technical Details

This PowerShell script performs the following actions:

  • It reads the contents of a text file named “migrate_user.txt” located at “c:\temp” and assigns the content to the variable $User.
  • It iterates over each item in the $User variable using a foreach loop, assigning each item to the variable $UItem.
  • Within the loop, it concatenates the value of $UItem with the string “@customer.com” and assigns the resulting User Principal Name (UPN) to the variable $UPN.
  • It retrieves the Active Directory user information for the user specified by $UItem using the cmdlet Get-ADUser with the -Identity parameter.
    – The -properties proxyaddresses parameter specifies that the “proxyaddresses” property should be included in the output.
    – The select -expandproperty proxyaddresses command expands and displays the values of the “proxyaddresses” property.
  • It retrieves and displays the target address for the user specified by $UItem using the Get-ADUser cmdlet with the -pr targetaddress parameter.
    – The fl targetaddress command formats and displays the value of the “targetaddress” property.
  • It retrieves and displays the User Principal Name (UPN) for the user specified by $UItem using the Get-ADUser cmdlet with the -pr UserPrincipalName parameter.
    – The fl UserPrincipalName command formats and displays the value of the “UserPrincipalName” property.

In summary, the script reads a list of user names from a text file, retrieves specific properties (proxyaddresses, targetaddress, UserPrincipalName) of each user from Active Directory, and displays the values of these properties for each user.

The Script

$User = Get-Content “c:\temp\migrate_user.txt”
ForEach ($UItem in $User){

$UPN = $UItem + “@customer.com”
get-ADUser -Identity “$UItem” -properties proxyaddresses | select -expandproperty proxyaddresses
get-aduser “$UItem” -pr targetaddress |fl targetaddress
get-aduser “$UItem” -pr UserPrincipalName |fl UserPrincipalName
}

********************

Change “customer.com” to your domain suffix or whatever domain you are working in.

The list containing users should be formatted as:  (using user ID’s pulled from AD)

Ctest1

Ctest2

User1

Stest3

Save it as a CR/LF text file.