首页 > 代码库 > 【转载】Powershell设置世纪互联Office365嵌套组发送权限

【转载】Powershell设置世纪互联Office365嵌套组发送权限

 1 Start-Transcript ".\Set-GroupSendPermisionLog.txt" -Force 2  3 function Get-DLMemberRecurse 4 { 5     $group=get-distributiongroupmember $args[0] -ResultSize unlimited 6     foreach ($varTemp in $group) 7     { 8         $varTemp 9         if ($varTemp.RecipientType -like "Mail*Group")10         {11             $members += $varTemp.Identity12             Get-DLMemberRecurse $varTemp.Identity13         }14     }15     return $members16 }17 18 $CsvPath = ".\Set-GroupSendPermisionList.csv"19 20 $Users = import-csv $CsvPath21 22 foreach ($User in $Users) 23 {24     $groupname=$User.Group25     $groupname26 27     if (!(get-distributiongroup $groupname))28     {29         echo "Group not found"30     } else {31         echo "Group found"32         Get-DLMemberRecurse $groupname | where-Object {$_.RecipientType -like "Mail*Group"} | select name | export-csv -NoTypeInformation -Encoding utf8 -path .\Set-GroupSendPermision.csv33         $content=Get-Content -Encoding utf8 -Path .\Set-GroupSendPermision.csv | Select -Skip 134         $content=$content.Replace("`"","")35         #$content36         $dup=($content | Measure-Object).count37         $dup38         echo -----------------------------------------------39         $content=$content | sort | get-unique40         #$content41         $nodup=($content | Measure-Object).count42         $nodup43         echo ===============================================44         for($i=1;$i -le $nodup;$i++)45         {46             $i47             echo 148             if ($nodup -eq 1)49             {50             $Identity=$content51             }52             else53             {54             $Identity=$content[$i-1]55             }56             echo 257             $Identity58             echo 359             (Get-DistributionGroup -identity $Identity).AcceptMessagesOnlyFromSendersOrMembers60             echo 461             #Set-DistributionGroup -Identity $Identity -AcceptMessagesOnlyFromSendersOrMembers ((Get-DistributionGroup -identity $Identity).AcceptMessagesOnlyFromSendersOrMembers +"$Gmember") -BypassSecurityGroupManagerCheck62             echo *******************************63         }64     }65     echo ///////////////////////////////////////////////////////////////////////////////66 }67 68 get-pssession | remove-pssession69 Stop-Transcript


CSV格式
User,Group
user1,group1
user1,group2
user1,group3
user2,group1
user3,group3 

http://www.smallrascal.cn/smallrascal/article.asp?id=2082    

【转载】Powershell设置世纪互联Office365嵌套组发送权限