Merge pull request #213 from soyalejolopez/master

New script: Get-GroupsMembersManagers
This commit is contained in:
Alejandro Lopez 2024-07-26 16:13:34 -05:00 коммит произвёл GitHub
Родитель 4b9fb1afc9 44b531a6ab
Коммит 70e3becc68
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 151 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,91 @@
<#
.DESCRIPTION
###############Disclaimer#####################################################
The sample scripts are not supported under any Microsoft standard support
program or service. The sample scripts are provided AS IS without warranty
of any kind. Microsoft further disclaims all implied warranties including,
without limitation, any implied warranties of merchantability or of fitness for
a particular purpose. The entire risk arising out of the use or performance of
the sample scripts and documentation remains with you. In no event shall
Microsoft, its authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever (including,
without limitation, damages for loss of business profits, business interruption,
loss of business information, or other pecuniary loss) arising out of the use
of or inability to use the sample scripts or documentation, even if Microsoft
has been advised of the possibility of such damages.
###############Disclaimer#####################################################
Purpose:
-The purpose of this script is to generate a report of Groups their members and their managers from Entra. This can be used to build the Organizational Data file which is later uploaded into M365 or Viva Advanced Insights.
REQUIREMENTS:
-Microsoft Graph Module: https://learn.microsoft.com/en-us/powershell/microsoftgraph/installation?view=graph-powershell-1.0
VERSION:
-07262024: V1
AUTHOR(S):
-Alejandro Lopez - Alejanl@Microsoft.com
-Dean Cron - DeanCron@microsoft.com
.EXAMPLE
Get members from all groups
.\Get-GroupsMembersManagers.ps1
#>
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Connect to Microsoft Graph
Write-Host "Connecting to Microsoft Graph..." -foregroundcolor "Yellow"
Connect-MgGraph -Scopes "Group.Read.All", "User.Read.All"
# Get all groups
Write-Host "Get All Groups. This might take some time..." -foregroundcolor "Yellow"
$groups = Get-MgGroup -All
# Prepare an array to hold user details
$userDetails = @()
$i=1
# Iterate over each group to get members
foreach ($group in $groups) {
Write-Host "Processed Group: $i of $($Groups.Count)" -foregroundcolor "Yellow"
# Get members of the group
$members = Get-MgGroupMember -GroupId $group.Id -All
# For each member, get the required details
foreach ($memberId in $members.Id) {
try{
$user = Get-MgUser -UserId $memberId -Property ID,DisplayName,UserPrincipalName,Department -ExpandProperty Manager
$managerUpn = $null
try {
$managerUpn = $user.Manager.AdditionalProperties['userPrincipalName']
} catch {
Write-Host "Manager not found for user: $($user.DisplayName)"
}
}
catch{Write-Host "Unable to get details for this account: $($memberId)"}
# Add user details to the array
$userDetails += [PSCustomObject]@{
GroupName = $group.DisplayName
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
Department = $user.Department
ManagerUPN = $managerUpn
}
}
$i++
}
# Export the user details to a CSV file
try{
$userDetails | Export-Csv -Path "EntraGroupMembersExport.csv" -NoTypeInformation
Write-Host "Finished processing. See results here: .\EntraGroupMembersExport.csv" -foregroundcolor "Yellow"
}
catch{Write-Host "Hit error while exporting results: $($_)"}
# Disconnect from Microsoft Graph
Write-Host "Disconnecting from Microsoft Graph..." -foregroundcolor "Yellow"
Disconnect-MgGraph

Просмотреть файл

@ -0,0 +1,60 @@
# Microsoft FastTrack Open Source - Get-GroupsMembersManagers.ps1
This sample script generates a report of Groups, their members and their managers from Entra. This can be used to build the Organizational Data file which is later uploaded into M365 or Viva Advanced Insights.
## Usage
### Pre-Requisites
- [Microsoft Graph Module](https://learn.microsoft.com/en-us/powershell/microsoftgraph/installation?view=graph-powershell-1.0)
### Parameters
None
### Output
The following properties are exported:
|GroupName|DisplayName|UserPrincipalName|Department|ManagerUPN
### Execution
Run the script like so:
.\Get-GroupsMembersManagers.ps1
## Applies To
- M365 / Organizational Data Import / Viva Insights
## Author
|Author|Original Publish Date
|----|--------------------------
|Alejandro Lopez, Microsoft|July 26th,2024|
|Dean Cron, Microsoft|July 26th, 2024|
## Issues
Please report any issues you find to the [issues list](https://github.com/microsoft/FastTrack/issues).
## Support Statement
The scripts, samples, and tools made available through the FastTrack Open Source initiative are provided as-is. These resources are developed in partnership with the community and do not represent official Microsoft software. As such, support is not available through premier or other Microsoft support channels. If you find an issue or have questions please reach out through the issues list and we'll do our best to assist, however there is no associated SLA.
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Legal Notices
Microsoft and any contributors grant you a license to the Microsoft documentation and other content in this repository under the [MIT License](https://opensource.org/licenses/MIT), see the [LICENSE](LICENSE) file, and grant you a license to any code in the repository under the [MIT License](https://opensource.org/licenses/MIT), see the [LICENSE-CODE](LICENSE-CODE) file.
Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.
Privacy information can be found at https://privacy.microsoft.com/en-us/
Microsoft and any contributors reserve all others rights, whether under their respective copyrights, patents,
or trademarks, whether by implication, estoppel or otherwise.