Last active
September 14, 2022 16:26
-
-
Save hansgafriedzal/1161d77353c2b53b7b99bbc60aee8247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$timestamp = Get-Date -format "yyyyMMddHHmmss" | |
Get-MgUser -All ` | |
-Filter 'accountEnabled eq true' ` | |
-Property AccountEnabled, OnPremisesUserPrincipalName, UserPrincipalName, DisplayName, CompanyName, UserId ` | |
-ExpandProperty Manager | foreach{ | |
[pscustomobject] @{ | |
Id = $_.Id | |
UserPrincipalName = $_.UserPrincipalName | |
DisplayName = $_.DisplayName | |
CompanyName = $_.CompanyName | |
AccountEnabled = $_.AccountEnabled | |
ManagerId = $_.Manager.Id | |
ManagerUserPrincipalName = $_.Manager.AdditionalProperties.userPrincipalName | |
ManagerDisplayName = $_.Manager.AdditionalProperties.displayName | |
ManagerAccountEnabled = $_.Manager.AdditionalProperties.accountEnabled | |
ManagerCompanyName = $_.Manager.AdditionalProperties.companyName | |
} | where ManagerUserPrincipalName -NE $null | |
} | Export-Csv "Get-MgUser_$timestamp.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment