mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 08:25:20 +00:00
Get MFA Status using MS Graph
Get MFA Status using MS Graph
This commit is contained in:
parent
7cfed4fc8e
commit
738778fe4c
@ -1,4 +1,26 @@
|
|||||||
|
<#
|
||||||
|
=============================================================================================
|
||||||
|
Name: Export Office 365 users' MFA status using Microsoft Graph PowerShell
|
||||||
|
Description: This script exports O365 users MFA status report to CSV file
|
||||||
|
Version: 1.0
|
||||||
|
Website: o365reports.com
|
||||||
|
Script by: O365Reports Team
|
||||||
|
|
||||||
|
Script Highlights :
|
||||||
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
1. The script exports MFA status for all users.
|
||||||
|
2. You can filter results based on MFA status. I.e., you can export MFA enabled/disabled users separately.
|
||||||
|
3. Exports report to CSV file
|
||||||
|
4. You can filter the result to display Licensed users alone.
|
||||||
|
5. You can generate MFA report for sign-in allowed users only.
|
||||||
|
6. Shows MFA registration done through Conditional Access and Security Defaults too.
|
||||||
|
7. Automatically installs Microsoft Graph PowerShell module (if not installed already) upon your confirmation.
|
||||||
|
|
||||||
|
|
||||||
|
For detailed script execution: https://o365reports.com/2022/04/27/get-mfa-status-of-office-365-users-using-microsoft-graph-powershell
|
||||||
|
============================================================================================
|
||||||
|
#>
|
||||||
Param
|
Param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
@ -12,21 +34,22 @@ Param
|
|||||||
Function Connect_MgGraph
|
Function Connect_MgGraph
|
||||||
{
|
{
|
||||||
#Check for module installation
|
#Check for module installation
|
||||||
$Module=Get-Module -Name microsoft.graph -ListAvailable
|
$MsGraphBetaModule = Get-Module Microsoft.Graph.Beta -ListAvailable
|
||||||
if($Module.count -eq 0)
|
if($MsGraphBetaModule -eq $null)
|
||||||
{
|
{
|
||||||
Write-Host Microsoft Graph PowerShell SDK is not available -ForegroundColor yellow
|
Write-host "Important: Microsoft Graph Beta module is unavailable. It is mandatory to have this module installed in the system to run the script successfully."
|
||||||
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
$confirm = Read-Host Are you sure you want to install Microsoft Graph Beta module? [Y] Yes [N] No
|
||||||
if($Confirm -match "[yY]")
|
if($confirm -match "[yY]")
|
||||||
{
|
{
|
||||||
Write-host "Installing Microsoft Graph PowerShell module..."
|
Write-host "Installing Microsoft Graph Beta module..."
|
||||||
Install-Module Microsoft.Graph -Repository PSGallery -Scope CurrentUser -AllowClobber -Force
|
Install-Module Microsoft.Graph.Beta -Scope CurrentUser -AllowClobber
|
||||||
}
|
Write-host "Microsoft Graph Beta module is installed in the machine successfully" -ForegroundColor Magenta
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
Write-Host "Microsoft Graph PowerShell module is required to run this script. Please install module using Install-Module Microsoft.Graph cmdlet."
|
{
|
||||||
Exit
|
Write-host "Exiting. `nNote: Microsoft Graph Beta module must be available in your system to run the script" -ForegroundColor Red
|
||||||
}
|
Exit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#Disconnect Existing MgGraph session
|
#Disconnect Existing MgGraph session
|
||||||
if($CreateSession.IsPresent)
|
if($CreateSession.IsPresent)
|
||||||
@ -34,11 +57,11 @@ Function Connect_MgGraph
|
|||||||
Disconnect-MgGraph
|
Disconnect-MgGraph
|
||||||
}
|
}
|
||||||
#Connecting to MgGraph beta
|
#Connecting to MgGraph beta
|
||||||
Select-MgProfile -Name beta
|
|
||||||
Write-Host Connecting to Microsoft Graph...
|
Write-Host Connecting to Microsoft Graph...
|
||||||
Connect-MgGraph -Scopes "User.Read.All","UserAuthenticationMethod.Read.All"
|
Connect-MgGraph -Scopes "User.Read.All","UserAuthenticationMethod.Read.All"
|
||||||
}
|
}
|
||||||
Connect_MgGraph
|
Connect_MgGraph
|
||||||
|
Write-Host "`nNote: If you encounter module related conflicts, run the script in a fresh PowerShell window.`n" -ForegroundColor Yellow
|
||||||
if((Get-MgContext) -ne "")
|
if((Get-MgContext) -ne "")
|
||||||
{
|
{
|
||||||
Write-Host Connected to Microsoft Graph PowerShell using (Get-MgContext).Account account -ForegroundColor Yellow
|
Write-Host Connected to Microsoft Graph PowerShell using (Get-MgContext).Account account -ForegroundColor Yellow
|
||||||
@ -51,7 +74,7 @@ $ExportCount=0
|
|||||||
$Results=@()
|
$Results=@()
|
||||||
|
|
||||||
#Get all users
|
#Get all users
|
||||||
Get-MgUser -All -Filter "UserType eq 'Member'" | foreach {
|
Get-MgBetaUser -All -Filter "UserType eq 'Member'" | foreach {
|
||||||
$ProcessedUserCount++
|
$ProcessedUserCount++
|
||||||
$Name= $_.DisplayName
|
$Name= $_.DisplayName
|
||||||
$UPN=$_.UserPrincipalName
|
$UPN=$_.UserPrincipalName
|
||||||
@ -76,7 +99,7 @@ Get-MgUser -All -Filter "UserType eq 'Member'" | foreach {
|
|||||||
$MFAPhone="-"
|
$MFAPhone="-"
|
||||||
$MicrosoftAuthenticatorDevice="-"
|
$MicrosoftAuthenticatorDevice="-"
|
||||||
Write-Progress -Activity "`n Processed users count: $ProcessedUserCount "`n" Currently processing user: $Name"
|
Write-Progress -Activity "`n Processed users count: $ProcessedUserCount "`n" Currently processing user: $Name"
|
||||||
[array]$MFAData=Get-MgUserAuthenticationMethod -UserId $UPN
|
[array]$MFAData=Get-MgBetaUserAuthenticationMethod -UserId $UPN
|
||||||
$AuthenticationMethod=@()
|
$AuthenticationMethod=@()
|
||||||
$AdditionalDetails=@()
|
$AdditionalDetails=@()
|
||||||
|
|
||||||
@ -196,7 +219,7 @@ Get-MgUser -All -Filter "UserType eq 'Member'" | foreach {
|
|||||||
if((Test-Path -Path $ExportCSV) -eq "True")
|
if((Test-Path -Path $ExportCSV) -eq "True")
|
||||||
{
|
{
|
||||||
Write-Host `nThe output file contains $ExportCount users.
|
Write-Host `nThe output file contains $ExportCount users.
|
||||||
Write-Host `nThe Output file available in the current working directory with name: $ExportCSV -ForegroundColor Green
|
Write-Host `nThe Output file available in the current working directory with name: -NoNewline -Foregroundcolor Yellow; Write-Host $ExportCSV
|
||||||
Write-Host `n"For more Microsoft 365 PowerShell scripts, visit: https://o365reports.com"
|
Write-Host `n"For more Microsoft 365 PowerShell scripts, visit: https://o365reports.com"
|
||||||
$Prompt = New-Object -ComObject wscript.shell
|
$Prompt = New-Object -ComObject wscript.shell
|
||||||
$UserInput = $Prompt.popup("Do you want to open output file?",`
|
$UserInput = $Prompt.popup("Do you want to open output file?",`
|
||||||
@ -208,13 +231,7 @@ if((Test-Path -Path $ExportCSV) -eq "True")
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host No users found
|
Write-Host No users found.
|
||||||
}
|
}
|
||||||
|
Write-Host `n~~ Script prepared by AdminDroid Community ~~`n -ForegroundColor Green
|
||||||
<#
|
Write-Host "~~ Check out " -NoNewline -ForegroundColor Green; Write-Host "admindroid.com" -ForegroundColor Yellow -NoNewline; Write-Host " to get access to 1800+ Microsoft 365 reports. ~~" -ForegroundColor Green `n`n
|
||||||
=============================================================================================
|
|
||||||
Name: Export Office 365 users' MFA status using Microsoft Graph PowerShell
|
|
||||||
Website: o365reports.com
|
|
||||||
For detailed script execution: https://o365reports.com/2022/04/27/get-mfa-status-of-office-365-users-using-microsoft-graph-powershell
|
|
||||||
============================================================================================
|
|
||||||
#>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user