Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-module activedirectory
- Import-Module MSOnline
- $Username = "admin@yourdomain.edu"
- $Password = ConvertTo-SecureString password -AsPlainText -Force
- $LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
- $senderemail="noreply@demo.com"
- $subject="Your Direct Reports and Permission"
- $managerusers = Get-ADGroupMember -identity "Test_Department_Manager" | Select-Object SamAccountName, userprincipalname
- Foreach ($manager in $managerusers)
- {
- # Find all direct user reporting to manager
- $directreportusers = Get-ADuser $manager -property directreports | select SamAccountName
- $manageremail=Get-ADuser $manager | select userprincipalname
- Foreach ($user in $directreportusers)
- {
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
- Import-PSSession $Session
- $email=$user.Mail
- $permission=Get-MailboxPermission -Identity $email
- $cred = $LiveCred
- $body = $permission
- Send-MailMessage -To manageremail -from $senderemail -Subject $subject -Body $body -BodyAsHtml -smtpserver smtp.office365.com -usessl -Credential $cred -Port 587
- Remove-PSSession $Session
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement