Set-ExecutionPolicy unrestricted

$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}

                }

}

相关文章:

  • 2022-01-05
  • 2021-04-17
  • 2021-11-08
  • 2021-11-30
  • 2021-12-03
  • 2021-12-27
猜你喜欢
  • 2021-11-16
  • 2022-12-23
  • 2021-10-26
  • 2021-06-22
  • 2022-12-23
  • 2021-07-14
  • 2021-12-05
相关资源
相似解决方案