【转载】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.Identity
12             Get-DLMemberRecurse $varTemp.Identity
13         }
14     }
15     return $members
16 }
17 
18 $CsvPath = ".\Set-GroupSendPermisionList.csv"
19 
20 $Users = import-csv $CsvPath
21 
22 foreach ($User in $Users) 
23 {
24     $groupname=$User.Group
25     $groupname
26 
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.csv
33         $content=Get-Content -Encoding utf8 -Path .\Set-GroupSendPermision.csv | Select -Skip 1
34         $content=$content.Replace("`"","")
35         #$content
36         $dup=($content | Measure-Object).count
37         $dup
38         echo -----------------------------------------------
39         $content=$content | sort | get-unique
40         #$content
41         $nodup=($content | Measure-Object).count
42         $nodup
43         echo ===============================================
44         for($i=1;$i -le $nodup;$i++)
45         {
46             $i
47             echo 1
48             if ($nodup -eq 1)
49             {
50             $Identity=$content
51             }
52             else
53             {
54             $Identity=$content[$i-1]
55             }
56             echo 2
57             $Identity
58             echo 3
59             (Get-DistributionGroup -identity $Identity).AcceptMessagesOnlyFromSendersOrMembers
60             echo 4
61             #Set-DistributionGroup -Identity $Identity -AcceptMessagesOnlyFromSendersOrMembers ((Get-DistributionGroup -identity $Identity).AcceptMessagesOnlyFromSendersOrMembers +"$Gmember") -BypassSecurityGroupManagerCheck
62             echo *******************************
63         }
64     }
65     echo ///////////////////////////////////////////////////////////////////////////////
66 }
67 
68 get-pssession | remove-pssession
69 Stop-Transcript


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

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

posted @ 2014-10-20 11:10  Anderson.Ling  阅读(495)  评论(0编辑  收藏  举报