1 $NewUserPath = ".Office365AddUserToGroup.csv" 2 3 $NewUsers = import-csv $NewUserPath 4 5 foreach ($NewUser in $NewUsers) { 6 $Mail=$NewUser.Mail 7 $Mail 8 $Groups=$NewUser.Group 9 $Groups 10 11 $Groups.split(";") | ForEach { 12 $Group=$_ 13 $Group 14 Add-DistributionGroupMember $Group -Member $Mail -BypassSecurityGroupManagerCheck 15 } 16 echo ======================================================= 17 } 18 19 get-pssession | remove-pssession 20 21 Stop-Transcript
CSV格式:
Mail,Group
user1@contoso.com,all@contoso.com;hr@contoso.com
user2@contoso.com,all@contoso.com
user3@contoso.com,it@contoso.com;tech@contoso.com;admin@contoso.com