mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 16:35:19 +00:00
Dynamic Distribution Group Members report
Export Dynamic Distribution Group Members report
This commit is contained in:
parent
332d9f3c61
commit
079a76d750
@ -1,4 +1,14 @@
|
|||||||
#Accept input parameter
|
<#
|
||||||
|
=============================================================================================
|
||||||
|
Name: Export Dynamic Distribution Group Members Report
|
||||||
|
Version: 2.0
|
||||||
|
Website: o365reports.com
|
||||||
|
Script by: O365Reports Team
|
||||||
|
For detailed script execution: https://o365reports.com/2019/03/23/export-dynamic-distribution-group-members-to-csv/
|
||||||
|
============================================================================================
|
||||||
|
#>
|
||||||
|
|
||||||
|
#Accept input parameter
|
||||||
Param
|
Param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
@ -7,7 +17,7 @@ Param
|
|||||||
[int]$MinGroupMembersCount,
|
[int]$MinGroupMembersCount,
|
||||||
[string]$UserName,
|
[string]$UserName,
|
||||||
[string]$Password,
|
[string]$Password,
|
||||||
[Switch]$MFA
|
[Switch]$NoMFA
|
||||||
)
|
)
|
||||||
|
|
||||||
#Get group members
|
#Get group members
|
||||||
@ -59,6 +69,7 @@ Function Get_Members
|
|||||||
}
|
}
|
||||||
#Get Counts by RecipientTypeDetail
|
#Get Counts by RecipientTypeDetail
|
||||||
$RecipientTypeDetail=$Member.RecipientTypeDetails
|
$RecipientTypeDetail=$Member.RecipientTypeDetails
|
||||||
|
$MemberEmail=$Member.PrimarySMTPAddress
|
||||||
foreach($key in [object[]]$Recipienthash.Keys)
|
foreach($key in [object[]]$Recipienthash.Keys)
|
||||||
{
|
{
|
||||||
if(($RecipientTypeDetail -eq $key) -eq "true")
|
if(($RecipientTypeDetail -eq $key) -eq "true")
|
||||||
@ -96,70 +107,57 @@ Function Print_Output
|
|||||||
{
|
{
|
||||||
if($Print=1)
|
if($Print=1)
|
||||||
{
|
{
|
||||||
$Result=@{'DisplayName'=$DisplayName;'PrimarySmtpAddress'=$EmailAddress;'Alias'=$Alias;'Manager'=$Manager;'GroupMembersCount'=$Members.Count; 'Members'=$Member;'MemberType'=$RecipientTypeDetail}
|
$Result=@{'DisplayName'=$DisplayName;'PrimarySmtpAddress'=$EmailAddress;'Alias'=$Alias;'Manager'=$Manager;'GroupMembersCount'=$Members.Count; 'Members'=$Member; 'MemberEmail'= $MemberEmail; 'MemberType'=$RecipientTypeDetail}
|
||||||
$Results= New-Object PSObject -Property $Result
|
$Results= New-Object PSObject -Property $Result
|
||||||
$Results | Select-Object DisplayName,PrimarySmtpAddress,Alias,Manager,GroupMembersCount,Members,MemberType | Export-Csv -Path $ExportCSV -Notype -Append
|
$Results | Select-Object DisplayName,PrimarySmtpAddress,Alias,Manager,GroupMembersCount,Members,MemberEmail,MemberType | Export-Csv -Path $ExportCSV -Notype -Append
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function main()
|
Function main()
|
||||||
{
|
{
|
||||||
#Connect AzureAD and Exchange Online from PowerShell
|
|
||||||
Get-PSSession | Remove-PSSession
|
|
||||||
|
|
||||||
#Get a list of RecipientTypeDetail
|
#Get a list of RecipientTypeDetail
|
||||||
$RecipientTypeArray=Get-Content -Path .\RecipientTypeDetails.txt -ErrorAction Stop
|
$RecipientTypeArray=Get-Content -Path .\RecipientTypeDetails.txt -ErrorAction Stop
|
||||||
|
|
||||||
#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
|
||||||
{
|
|
||||||
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]")
|
if($Confirm -match "[yY]")
|
||||||
{
|
{
|
||||||
Write-Host Yes
|
Write-host "Installing Exchange Online PowerShell module"
|
||||||
Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application"
|
Install-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Force
|
||||||
|
Import-Module ExchangeOnlineManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Start-Process 'https://http://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
|
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
|
|
||||||
}
|
}
|
||||||
|
#Check for Azure AD module
|
||||||
|
$Module = Get-Module MsOnline -ListAvailable
|
||||||
|
if($Module.count -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host MSOnline module is not available -ForegroundColor yellow
|
||||||
|
$Confirm= Read-Host Are you sure you want to install the module? [Y] Yes [N] No
|
||||||
|
if($Confirm -match "[yY]")
|
||||||
|
{
|
||||||
|
Write-host "Installing MSOnline PowerShell module"
|
||||||
|
Install-Module MSOnline -Repository PSGallery -AllowClobber -Force
|
||||||
|
Import-Module MSOnline
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host Exchange Online PowerShell Module is required
|
Write-Host MSOnline module is required to generate the report.Please install module using Install-Module MSOnline cmdlet.
|
||||||
Start-Process 'https:http://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/'
|
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#Importing Exchange MFA Module
|
|
||||||
. "$MFAExchangeModule"
|
|
||||||
Write-Host Enter credential in prompt to connect to Exchange Online
|
|
||||||
Connect-EXOPSSession -WarningAction SilentlyContinue
|
|
||||||
Write-Host Connected to Exchange Online
|
|
||||||
Write-Host `nReport generation in progress...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Authentication using non-MFA
|
#Authentication using non-MFA
|
||||||
else
|
if($NoMFA.IsPresent)
|
||||||
{
|
{
|
||||||
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
#Storing credential in script for scheduling purpose/ Passing credential as parameter
|
||||||
if(($UserName -ne "") -and ($Password -ne ""))
|
if(($UserName -ne "") -and ($Password -ne ""))
|
||||||
@ -171,18 +169,29 @@ Function main()
|
|||||||
{
|
{
|
||||||
$Credential=Get-Credential -Credential $null
|
$Credential=Get-Credential -Credential $null
|
||||||
}
|
}
|
||||||
Connect-MsolService -Credential $credential
|
Write-Host "Connecting Azure AD..."
|
||||||
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
|
Connect-MsolService -Credential $Credential | Out-Null
|
||||||
Import-PSSession $Session -CommandName Get-DynamicDistributionGroup,Get-Recipient -FormatTypeName * -AllowClobber | Out-Null
|
Write-Host "Connecting Exchange Online PowerShell..."
|
||||||
|
Connect-ExchangeOnline -Credential $Credential
|
||||||
|
}
|
||||||
|
#Connect to Exchange Online and AzureAD module using MFA
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Connecting Exchange Online PowerShell..."
|
||||||
|
Connect-ExchangeOnline
|
||||||
|
Write-Host "Connecting Azure AD..."
|
||||||
|
Connect-MsolService | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Friendly DateTime conversion
|
||||||
|
if($friendlyTime.IsPresent)
|
||||||
|
{
|
||||||
|
If(((Get-Module -Name PowerShellHumanizer -ListAvailable).Count) -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host Installing PowerShellHumanizer for Friendly DateTime conversion
|
||||||
|
Install-Module -Name PowerShellHumanizer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Set output file
|
#Set output file
|
||||||
$ExportCSV=".\DynamicDistributionGroup-DetailedMembersReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv" #Detailed report
|
$ExportCSV=".\DynamicDistributionGroup-DetailedMembersReport_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv" #Detailed report
|
||||||
@ -191,7 +200,7 @@ Function main()
|
|||||||
|
|
||||||
$Result=""
|
$Result=""
|
||||||
$Results=@()
|
$Results=@()
|
||||||
$Count=0
|
$Count=1
|
||||||
|
|
||||||
#Check for input file
|
#Check for input file
|
||||||
if ($GroupNamesFile -ne "")
|
if ($GroupNamesFile -ne "")
|
||||||
@ -235,7 +244,8 @@ Function main()
|
|||||||
{
|
{
|
||||||
Write-Host No DynamicDistributionGroup found
|
Write-Host No DynamicDistributionGroup found
|
||||||
}
|
}
|
||||||
|
Write-Host "For more Office 365 reports, do check AdminDroid Office 365 reporting tool." -ForegroundColor Cyan
|
||||||
#Clean up session
|
#Clean up session
|
||||||
Get-PSSession | Remove-PSSession
|
Disconnect-ExchangeOnline -Confirm:$false -InformationAction Ignore -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
. main
|
. main
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user