Advertisement
Guest User

Untitled

a guest
May 24th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================================
  2. # AUTHOR:   Brad Wright
  3. # CO-AUTHOR:  Dan Shepard
  4. # DATE:     05-24-2018
  5. # Version   v1.1
  6. # COMMENT:  Used with MFA Office 365
  7. #===============================================================================================
  8.  
  9. #This powershell script will create 4 different files
  10. #InactiveUsers.csv - list of all accounts not used for 90+ days
  11. #list-admins.csv - list of all global admin accounts
  12. #MailboxDelegatePermissions.csv - list of all mailbox delegate permissions
  13. #MailForwardingRulesToExternalDomains - list of all user based rules
  14.  
  15. Clear-Host
  16. Write-Output "Blue Sprue Capital - Weekly report for Office 365"
  17. Write-Output "Please login to Office 365 with the Global Admin account"
  18.  
  19. #Connect to Office365
  20. $credential = Get-Credential
  21. Install-Module MsOnline
  22. Connect-MsolService -Credential $credential
  23. $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
  24. Import-PSSession $exchangeSession -DisableNameChecking
  25.  
  26. #Clear-Host
  27. Write-Output "This is going to take a while go get some coffee"
  28.  
  29.  
  30. ############ Delegates & Forwarding Rules ###############
  31.  
  32. #Find all users within Office 365
  33. $allUsers = @()
  34. $AllUsers = Get-MsolUser -All -EnabledFilter EnabledOnly | Where-Object {($_.UserPrincipalName -notlike "*#EXT#*")}
  35.  
  36. #Create arrays
  37. $UserInboxRules = @()
  38. $UserDelegates = @()
  39.  
  40. #Foreach for all users
  41. foreach ($User in $allUsers)
  42. {
  43.     Write-Host "Checking inbox rules and delegates for user: " $User.UserPrincipalName;
  44.     $UserInboxRules += Get-InboxRule -Mailbox $User.UserPrincipalname  |  Where-Object {($_.ForwardTo -ne $null) -or ($_.ForwardAsAttachmentTo -ne $null) -or ($_.RedirectsTo -ne $null)}
  45.     $UserDelegates += Get-MailboxPermission -Identity $User.UserPrincipalName  | Where-Object {($_.IsInherited -ne "True") -and ($_.User -notlike "*SELF*")}
  46. }
  47.  
  48. #export findings to a file
  49. $UserInboxRules | Select Enabled, Identity, Name, From, SentTo, CopyToFolder, DeleteMessage, ForwardTo, MailboxOwnerID | Export-Csv '~\Desktop\MailForwardingRulesToExternalDomains.csv' -NoType
  50. $UserDelegates | Select User, Identity, AccessRights | Export-Csv '~\Desktop\MailboxDelegatePermissions.csv' -NoType
  51.  
  52. ########## End Delegates & Forwarding Rules ############
  53.  
  54. ################## List Admin's ########################
  55.  
  56. #Which role we are looking for
  57. $role = Get-MsolRole -RoleName "Company Administrator"
  58.  
  59. #export findings to a file
  60. Get-MsolRoleMember -RoleObjectId $role.ObjectId | Select DisplayName, Emailaddress, IsLicensed, LastDirSyncTime, OverallProvisioningStatus, ValidationStatus |Export-CSV '~\Desktop\list-admins.csv' -NoType
  61.  
  62. ################ #End List Admin's #####################
  63.  
  64. ################ Inactive Accounts #####################
  65.  
  66. #http://www.itfunk.com/2017/01/27/powershell-to-find-inactive-user-accounts-in-office-365/
  67. Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | where {$_.LastLogonTime -lt ((get-date).AddDays(-90))} | Select displayname, lastlogontime | Export-csv '~\Desktop\InactiveUsers.csv' -NoType
  68.  
  69. ############## End Inactive Accounts ###################
  70. Clear-Host
  71. Write-Output "Blue Sprue Capital - Weekly report for Office 365"
  72. Write-Output "Finished, please check the main directory for the CSV files"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement