Thanks for posting your question in the Microsoft Q&A forum. Did you check the script generated by ChatGPT?
# Import the AzureAD module
Import-Module AzureAD
# Connect to Azure AD
Connect-AzureAD
# Get all users from Azure AD
$users = Get-AzureADUser -All $true
# Loop through each user and retrieve the required information
$userInfo = @()
foreach ($user in $users) {
$userPrincipalName = $user.UserPrincipalName
$displayName = $user.DisplayName
$userType = $user.UserType
$department = $user.Department
$employeeType = $user.EmployeeType
$mfaState = $user.StrongAuthenticationMethods.State
$mfaDefaultMethod = $user.StrongAuthenticationMethods.DefaultMethodType
$mfaPhoneNumber = $user.MobilePhone
$primarySMTP = $user.Mail
$aliases = $user.ProxyAddresses -join ','
$whenCreated = $user.WhenCreated
$creationType = $user.CreationType
$accountEnabled = $user.AccountEnabled
$manager = ($user.Manager -split ',')[0]
$companyName = $user.CompanyName
$identities = $user.Identities
$licenseType = $user.Licenses.LicenseProperties -join ','
$userInfo += [PSCustomObject]@{
UserPrincipalName = $userPrincipalName
DisplayName = $displayName
UserType = $userType
Department = $department
EmployeeType = $employeeType
MFAState = $mfaState
MFADefaultMethod = $mfaDefaultMethod
MFAPhoneNumber = $mfaPhoneNumber
PrimarySMTP = $primarySMTP
Aliases = $aliases
WhenCreated = $whenCreated
CreationType = $creationType
AccountEnabled = $accountEnabled
Manager = $manager
CompanyName = $companyName
Identities = $identities
LicenseType = $licenseType
}
}
# Output the user information
$userInfo | Export-Csv -Path "C:\Users\User\Documents\UserInfo.csv" -NoTypeInformation
# Disconnect from Azure AD
Disconnect-AzureAD
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **