$cred = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
get-distributiongroup -resultsize unlimited |ft name, managedby
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
If($members) {
$members=$members + ";" + $_.Name
} Else {
$members=$_.Name
}
}
导出组一
$Groups | ForEach-Object {
$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
If($members) {
$members=$members + ";" + $_.Name
} Else {
$members=$_.Name
}
}
New-Object -TypeName PSObject -Property @{
GroupName = $group
Members = $members
}
} | Export-CSV "D:\Distribution-Group-Members.csv" -NoTypeInformation -Encoding UTF8
导出组二
$file_name = "D:\Groups.csv"
add-content -value ("Distribution List"+","+"Display Name"+","+"Group Type"+","+"Time"+","+"Message Approval"+","+"Member") -path $file_name
$DL=get-DistributionGroup
foreach ($_ in $DL)
{
$name = $_.DisplayName
$ID = $_.PrimarySmtpAddress
$Type = $_.RecipientType
$modified = $_.WhenChanged
$DLmember=get-DistributionGroupMember -identity $_.identity
foreach($_ in $DLmember)
{
$members = $_.PrimarySmtpAddress
add-content -value ($ID +","+$name +","+$Type +","+$modified +","+$members) -path $file_name}
}
}
转载自原文链接, 如需删除请联系管理员。
原文链接:导出Office365中的组及成员,转载请注明来源!