mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 16:35:19 +00:00
Export Distribution Group Members Report
Export Distribution Group Members Report
This commit is contained in:
parent
fc5eb47aec
commit
c9f81c5191
@ -1,10 +1,17 @@
|
|||||||
Param
|
<#
|
||||||
|
=============================================================================================
|
||||||
|
Name: Get distribution group members report
|
||||||
|
Version: 3.0
|
||||||
|
Website: o365reports.com
|
||||||
|
For detailed script execution: https://o365reports.com/2019/05/23/export-office-365-distribution-group-members-csv/
|
||||||
|
============================================================================================
|
||||||
|
#>
|
||||||
|
Param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[string]$GroupNamesFile,
|
[string]$GroupNamesFile,
|
||||||
[switch]$IsEmpty,
|
[switch]$IsEmpty,
|
||||||
[int]$MinGroupMembersCount,
|
[int]$MinGroupMembersCount,
|
||||||
[switch]$MFA,
|
|
||||||
[Nullable[boolean]]$ExternalSendersBlocked = $null,
|
[Nullable[boolean]]$ExternalSendersBlocked = $null,
|
||||||
[string]$UserName,
|
[string]$UserName,
|
||||||
[string]$Password
|
[string]$Password
|
||||||
@ -151,66 +158,35 @@ Function main()
|
|||||||
#Clean up session
|
#Clean up session
|
||||||
Get-PSSession | Remove-PSSession
|
Get-PSSession | Remove-PSSession
|
||||||
|
|
||||||
#Authentication using MFA
|
#Check for EXO v2 module inatallation
|
||||||
if($MFA.IsPresent)
|
$Module = Get-Module ExchangeOnlineManagement -ListAvailable
|
||||||
|
if($Module.count -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host Exchange Online PowerShell V2 module is not available -ForegroundColor yellow
|
||||||
|
$Confirm= Read-Host Are you sure you want to install module? [Y] Yes [N] No
|
||||||
|
if($Confirm -match "[yY]")
|
||||||
|
{
|
||||||
|
Write-host "Installing Exchange Online PowerShell module"
|
||||||
|
Install-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Force
|
||||||
|
Import-Module ExchangeOnlineManagement
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host EXO V2 module is required to connect Exchange Online.Please install module using Install-Module ExchangeOnlineManagement cmdlet.
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host Connecting to Exchange Online...
|
||||||
|
#Storing credential in script for scheduling purpose/ Passing credential as parameter - Authentication using non-MFA account
|
||||||
|
if(($UserName -ne "") -and ($Password -ne ""))
|
||||||
{
|
{
|
||||||
$MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
|
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
||||||
If ($MFAExchangeModule -eq $null)
|
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
||||||
{
|
Connect-ExchangeOnline -Credential $Credential
|
||||||
Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow
|
|
||||||
|
|
||||||
Write-Host You can install module using below blog : `nLink `nOR you can install module directly by entering "Y"`n
|
|
||||||
$Confirm= Read-Host Are you sure you want to install module directly? [Y] Yes [N] No
|
|
||||||
if($Confirm -match "[yY]")
|
|
||||||
{
|
|
||||||
Write-Host Yes
|
|
||||||
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Start-Process 'https://http://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Write-Host Exchange Online PowerShell Module is required
|
|
||||||
Start-Process 'https://http://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
|
|
||||||
Write-Host `nReport generation in progress...
|
|
||||||
}
|
}
|
||||||
#Authentication using non-MFA
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
Connect-ExchangeOnline
|
||||||
if(($UserName -ne "") -and ($Password -ne ""))
|
|
||||||
{
|
|
||||||
$SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force
|
|
||||||
$Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$Credential=Get-Credential -Credential $null
|
|
||||||
}
|
|
||||||
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
|
|
||||||
Import-PSSession $Session -CommandName Get-DistributionGroup,Get-DistributionGroupMember -FormatTypeName * -AllowClobber | Out-Null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Set output file
|
#Set output file
|
||||||
@ -250,6 +226,7 @@ Function main()
|
|||||||
{
|
{
|
||||||
Write-Host Detailed report available in: $ExportCSV
|
Write-Host Detailed report available in: $ExportCSV
|
||||||
Write-host Summary report available in: $ExportSummaryCSV
|
Write-host Summary report available in: $ExportSummaryCSV
|
||||||
|
Write-Host `nCheck out """AdminDroid Office 365 Reporting tool""" to get access to 1500+ Office 365 reports.`n -ForegroundColor Green
|
||||||
$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?",`
|
||||||
0,"Open Output File",4)
|
0,"Open Output File",4)
|
||||||
@ -263,8 +240,8 @@ Function main()
|
|||||||
{
|
{
|
||||||
Write-Host No DistributionGroup found
|
Write-Host No DistributionGroup found
|
||||||
}
|
}
|
||||||
#Clean up session
|
#Disconnect Exchange Online session
|
||||||
Get-PSSession | Remove-PSSession
|
Disconnect-ExchangeOnline -Confirm:$false -InformationAction Ignore -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
}
|
}
|
||||||
. main
|
. main
|
||||||
Loading…
x
Reference in New Issue
Block a user