This script allows you to input a username, and then it checks the user’s license information by querying Azure AD and displays the DisplayName and Licenses properties for that user in a formatted list.

Technical Details

The provided script is a PowerShell script that performs the following tasks:

  • It prompts the user to enter a username (User Name) using the `Read-Host` cmdlet. The entered username is stored in the variable `$user`.
  • It constructs the User Principal Name (UPN) by concatenating the `$user` with the domain name “@yourdomain.com”. The UPN is then stored in the variable `$UPN`.
  • It uses the `Get-MsolUser` cmdlet to retrieve information about the user from Azure Active Directory (Azure AD) based on the provided UPN. The `-UserPrincipalName` parameter is used to specify the UPN of the user to fetch.
  • The results of the `Get-MsolUser` cmdlet are then formatted using the `Format-List` cmdlet to display the user’s DisplayName and Licenses properties in a list format. The `Format-List` cmdlet formats the output in a readable way, showing each property on a separate line.

The Script

$user = Read-Host -Prompt ‘User Name’
#(license check)
$UPN=($user + “@yourdomain.com”)
Get-MsolUser -UserPrincipalName $UPN | Format-List DisplayName,Licenses