mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 16:35:19 +00:00
Export Office 365 Users Logon History Report
Export Office 365 Users Logon History Report
This commit is contained in:
parent
78277f7b71
commit
576def47bb
@ -1,9 +1,16 @@
|
|||||||
Param
|
<#
|
||||||
|
=============================================================================================
|
||||||
|
Name: Office 365 User Login History Report
|
||||||
|
Website: o365reports.com
|
||||||
|
Version: 3.0
|
||||||
|
For detailed Script execution: https://o365reports.com/2019/12/23/export-office-365-users-logon-history-report/
|
||||||
|
============================================================================================
|
||||||
|
#>
|
||||||
|
Param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[switch]$Success,
|
[switch]$Success,
|
||||||
[switch]$Failed,
|
[switch]$Failed,
|
||||||
[switch]$MFA,
|
|
||||||
[Nullable[DateTime]]$StartDate,
|
[Nullable[DateTime]]$StartDate,
|
||||||
[Nullable[DateTime]]$EndDate,
|
[Nullable[DateTime]]$EndDate,
|
||||||
[string]$UserName,
|
[string]$UserName,
|
||||||
@ -39,63 +46,35 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#Authentication using MFA
|
#Check for EXO v2 module inatallation
|
||||||
if($MFA.IsPresent)
|
$Module = Get-Module ExchangeOnlineManagement -ListAvailable
|
||||||
|
if($Module.count -eq 0)
|
||||||
{
|
{
|
||||||
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
Write-Host Exchange Online PowerShell V2 module is not available -ForegroundColor yellow
|
||||||
If ($MFAExchangeModule -eq $null)
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
||||||
|
if($Confirm -match "[yY]")
|
||||||
{
|
{
|
||||||
Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow
|
Write-host "Installing Exchange Online PowerShell module"
|
||||||
Write-Host You can manually install module using below blog : `nhttps://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/ `nOR you can install module directly by entering "Y"`n
|
Install-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Force
|
||||||
$Confirm= Read-Host `nAre you sure you want to install module directly? [Y] Yes [N] No
|
Import-Module ExchangeOnlineManagement
|
||||||
if($Confirm -match "[Y]")
|
|
||||||
{
|
|
||||||
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
Write-Host EXO V2 module is required to connect Exchange Online.Please install module using Install-Module ExchangeOnlineManagement cmdlet.
|
||||||
Exit
|
|
||||||
}
|
|
||||||
$Confirmation= Read-Host Have you installed Exchange Online MFA Module? [Y] Yes [N] No
|
|
||||||
if($Confirmation -match "[yY]")
|
|
||||||
{
|
|
||||||
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
|
||||||
If ($MFAExchangeModule -eq $null)
|
|
||||||
{
|
|
||||||
Write-Host Exchange Online MFA module is not available -ForegroundColor red
|
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
Write-Host Connecting to Exchange Online...
|
||||||
{
|
#Storing credential in script for scheduling purpose/ Passing credential as parameter - Authentication using non-MFA account
|
||||||
Write-Host Exchange Online PowerShell Module is required
|
|
||||||
Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Importing Exchange MFA Module
|
|
||||||
. "$MFAExchangeModule"
|
|
||||||
Write-Host Enter credential in prompt to connect to Exchange Online
|
|
||||||
Connect-EXOPSSession -WarningAction SilentlyContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
#Authentication using non-MFA
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
|
||||||
if(($AdminName -ne "") -and ($Password -ne ""))
|
if(($AdminName -ne "") -and ($Password -ne ""))
|
||||||
{
|
{
|
||||||
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
||||||
$Credential = New-Object System.Management.Automation.PSCredential $AdminName,$SecuredPassword
|
$Credential = New-Object System.Management.Automation.PSCredential $AdminName,$SecuredPassword
|
||||||
|
Connect-ExchangeOnline -Credential $Credential
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$Credential=Get-Credential -Credential $null
|
Connect-ExchangeOnline
|
||||||
}
|
|
||||||
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue
|
|
||||||
Import-PSSession $Session -AllowClobber -WarningAction SilentlyContinue | Out-Null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$OutputCSV=".\AuditLog_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
$OutputCSV=".\AuditLog_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user