Skip to content

Instantly share code, notes, and snippets.

@ktskumar
Created June 12, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktskumar/536f438912b15069de03720f84f72ad0 to your computer and use it in GitHub Desktop.
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
$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