Created
June 12, 2021 16:57
-
-
Save ktskumar/536f438912b15069de03720f84f72ad0 to your computer and use it in GitHub Desktop.
Export all the users with no birthday value set in the Profile using Microsoft 365 CLI
This file contains 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
$outputfilepath = "< OUTPUT PATH WITH FILENAME.csv >" | |
Write-host 'ensure logged in' | |
$m365Status = m365 status | |
if ($m365Status -eq "Logged Out") { | |
m365 login | |
} | |
# Fetch all AAD users from Microsoft 365 | |
$allusers = m365 aad user list --properties 'displayName,userPrincipalName,accountEnabled' -o json | ConvertFrom-Json | |
$NoBirthdayUsers = @() | |
foreach ($user in $allusers) { | |
$userprofile = m365 aad user get --userName $user.userPrincipalName --properties birthday -o json | ConvertFrom-Json | |
$userbd = Get-Date $userprofile.birthday | |
If ($nulldate -eq $userbd) { | |
Write-Host $user.displayName 'Birthday not set!' | |
$userObject = New-Object -TypeName PSObject | |
$userObject | Add-Member -MemberType NoteProperty -Name 'Display Name' -Value $user.displayName | |
$userObject | Add-Member -MemberType NoteProperty -Name 'User Principal Name' -Value $user.userPrincipalName | |
$userObject | Add-Member -MemberType NoteProperty -Name 'Account Enabled' -Value $user.accountEnabled | |
$NoBirthdayUsers += $userObject | |
} | |
else { | |
Write-Host $user.displayName 'Birthday set!' | |
} | |
} | |
### | |
$NoBirthdayUsers | Export-Csv -Path $outputfilepath -NoTypeInformation | |
Write-Host 'Complete' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment