Created
February 19, 2021 02:58
-
-
Save YasuoFromDeadScream/f3ea2b2d49d3fc7f610a2eaa54cb58e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRelation($targetRecipient, $departmentName){ | |
$org = New-Object PSObject | Select-Object 社員名,所属部署 | |
if($targetRecipient.RecipientType -eq "MailUniversalSecurityGroup"){ | |
$departmentName = $targetRecipient.DisplayName | |
# メンバー情報の取得 | |
Get-DistributionGroupMember $targetRecipient.Alias | | |
# 取得したメンバをユーザ、グループの順でソート | |
Select-Object Alias, DisplayName, PrimarySmtpAddress, RecipientType, @{L="SortIndex"; E={switch($_.RecipientType){ | |
"UserMailBox"{0} | |
"MailUniversalSecurityGroup"{1} | |
}}} | | |
Sort-Object -Property SortIndex, DisplayName | | |
# 取得したメンバを使用して再帰処理 | |
ForEach-Object {getRelation $_ $departmentName} | |
}else{ | |
$org.社員名 = $targetRecipient.DisplayName -join "`r`n" | |
$org.所属部署 = $departmentName -join "`r`n" | |
[void]$orglist.Add(($org | Select-Object 社員名,所属部署 )) | |
} | |
} | |
Connect-ExchangeOnline -ShowBanner:$false | out-null | |
$global:orglist = New-Object System.Collections.ArrayList | |
$rooInfo = (Get-OrganizationConfig).HierarchicalAddressBookRoot | |
getRelation (Get-DistributionGroup $rooInfo) | |
$orglist | export-csv .\社員所属部署に関する情報.csv -NoTypeInformation -Encoding UTF8 | |
Disconnect-ExchangeOnline -Confirm:$false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment