Advertisement
Guest User

O365PoshHtmlReport

a guest
Jun 24th, 2018
1,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $CompanyLogo = "http://thelazyadministrator.com/wp-content/uploads/2018/06/logo-2-e1529684959389.png"
  2. $RightLogo = "http://thelazyadministrator.com/wp-content/uploads/2018/06/amd.png"
  3. $ReportSavePath = "C:\Automation\"
  4.  
  5.  
  6. $credential = Get-Credential -Message "Please enter your Office 365 credentials"
  7. Import-Module AzureAD
  8. Connect-AzureAD -Credential $credential
  9. $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
  10. Import-PSSession $exchangeSession -AllowClobber
  11.  
  12. $Table = New-Object 'System.Collections.Generic.List[System.Object]'
  13. $LicenseTable = New-Object 'System.Collections.Generic.List[System.Object]'
  14. $UserTable = New-Object 'System.Collections.Generic.List[System.Object]'
  15. $SharedMailboxTable = New-Object 'System.Collections.Generic.List[System.Object]'
  16. $GroupTypetable = New-Object 'System.Collections.Generic.List[System.Object]'
  17. $IsLicensedUsersTable = New-Object 'System.Collections.Generic.List[System.Object]'
  18. $ContactTable = New-Object 'System.Collections.Generic.List[System.Object]'
  19. $MailUser = New-Object 'System.Collections.Generic.List[System.Object]'
  20. $ContactMailUserTable = New-Object 'System.Collections.Generic.List[System.Object]'
  21. $RoomTable = New-Object 'System.Collections.Generic.List[System.Object]'
  22. $EquipTable = New-Object 'System.Collections.Generic.List[System.Object]'
  23. $GlobalAdminTable = New-Object 'System.Collections.Generic.List[System.Object]'
  24. $StrongPasswordTable = New-Object 'System.Collections.Generic.List[System.Object]'
  25. $CompanyInfoTable = New-Object 'System.Collections.Generic.List[System.Object]'
  26. $MessageTraceTable = New-Object 'System.Collections.Generic.List[System.Object]'
  27. $DomainTable = New-Object 'System.Collections.Generic.List[System.Object]'
  28.  
  29. $Sku = @{
  30.     "O365_BUSINESS_ESSENTIALS"             = "Office 365 Business Essentials"
  31.     "O365_BUSINESS_PREMIUM"                = "Office 365 Business Premium"
  32.     "DESKLESSPACK"                         = "Office 365 (Plan K1)"
  33.     "DESKLESSWOFFPACK"                     = "Office 365 (Plan K2)"
  34.     "LITEPACK"                             = "Office 365 (Plan P1)"
  35.     "EXCHANGESTANDARD"                     = "Office 365 Exchange Online Only"
  36.     "STANDARDPACK"                         = "Enterprise Plan E1"
  37.     "STANDARDWOFFPACK"                     = "Office 365 (Plan E2)"
  38.     "ENTERPRISEPACK"                       = "Enterprise Plan E3"
  39.     "ENTERPRISEPACKLRG"                    = "Enterprise Plan E3"
  40.     "ENTERPRISEWITHSCAL"                   = "Enterprise Plan E4"
  41.     "STANDARDPACK_STUDENT"                 = "Office 365 (Plan A1) for Students"
  42.     "STANDARDWOFFPACKPACK_STUDENT"         = "Office 365 (Plan A2) for Students"
  43.     "ENTERPRISEPACK_STUDENT"               = "Office 365 (Plan A3) for Students"
  44.     "ENTERPRISEWITHSCAL_STUDENT"           = "Office 365 (Plan A4) for Students"
  45.     "STANDARDPACK_FACULTY"                 = "Office 365 (Plan A1) for Faculty"
  46.     "STANDARDWOFFPACKPACK_FACULTY"         = "Office 365 (Plan A2) for Faculty"
  47.     "ENTERPRISEPACK_FACULTY"               = "Office 365 (Plan A3) for Faculty"
  48.     "ENTERPRISEWITHSCAL_FACULTY"           = "Office 365 (Plan A4) for Faculty"
  49.     "ENTERPRISEPACK_B_PILOT"               = "Office 365 (Enterprise Preview)"
  50.     "STANDARD_B_PILOT"                     = "Office 365 (Small Business Preview)"
  51.     "VISIOCLIENT"                          = "Visio Pro Online"
  52.     "POWER_BI_ADDON"                       = "Office 365 Power BI Addon"
  53.     "POWER_BI_INDIVIDUAL_USE"              = "Power BI Individual User"
  54.     "POWER_BI_STANDALONE"                  = "Power BI Stand Alone"
  55.     "POWER_BI_STANDARD"                    = "Power-BI Standard"
  56.     "PROJECTESSENTIALS"                    = "Project Lite"
  57.     "PROJECTCLIENT"                        = "Project Professional"
  58.     "PROJECTONLINE_PLAN_1"                 = "Project Online"
  59.     "PROJECTONLINE_PLAN_2"                 = "Project Online and PRO"
  60.     "ProjectPremium"                       = "Project Online Premium"
  61.     "ECAL_SERVICES"                        = "ECAL"
  62.     "EMS"                                  = "Enterprise Mobility Suite"
  63.     "RIGHTSMANAGEMENT_ADHOC"               = "Windows Azure Rights Management"
  64.     "MCOMEETADV"                           = "PSTN conferencing"
  65.     "SHAREPOINTSTORAGE"                    = "SharePoint storage"
  66.     "PLANNERSTANDALONE"                    = "Planner Standalone"
  67.     "CRMIUR"                               = "CMRIUR"
  68.     "BI_AZURE_P1"                          = "Power BI Reporting and Analytics"
  69.     "INTUNE_A"                             = "Windows Intune Plan A"
  70.     "PROJECTWORKMANAGEMENT"                = "Office 365 Planner Preview"
  71.     "ATP_ENTERPRISE"                       = "Exchange Online Advanced Threat Protection"
  72.     "EQUIVIO_ANALYTICS"                    = "Office 365 Advanced eDiscovery"
  73.     "AAD_BASIC"                            = "Azure Active Directory Basic"
  74.     "RMS_S_ENTERPRISE"                     = "Azure Active Directory Rights Management"
  75.     "AAD_PREMIUM"                          = "Azure Active Directory Premium"
  76.     "MFA_PREMIUM"                          = "Azure Multi-Factor Authentication"
  77.     "STANDARDPACK_GOV"                     = "Microsoft Office 365 (Plan G1) for Government"
  78.     "STANDARDWOFFPACK_GOV"                 = "Microsoft Office 365 (Plan G2) for Government"
  79.     "ENTERPRISEPACK_GOV"                   = "Microsoft Office 365 (Plan G3) for Government"
  80.     "ENTERPRISEWITHSCAL_GOV"               = "Microsoft Office 365 (Plan G4) for Government"
  81.     "DESKLESSPACK_GOV"                     = "Microsoft Office 365 (Plan K1) for Government"
  82.     "ESKLESSWOFFPACK_GOV"                  = "Microsoft Office 365 (Plan K2) for Government"
  83.     "EXCHANGESTANDARD_GOV"                 = "Microsoft Office 365 Exchange Online (Plan 1) only for Government"
  84.     "EXCHANGEENTERPRISE_GOV"               = "Microsoft Office 365 Exchange Online (Plan 2) only for Government"
  85.     "SHAREPOINTDESKLESS_GOV"               = "SharePoint Online Kiosk"
  86.     "EXCHANGE_S_DESKLESS_GOV"              = "Exchange Kiosk"
  87.     "RMS_S_ENTERPRISE_GOV"                 = "Windows Azure Active Directory Rights Management"
  88.     "OFFICESUBSCRIPTION_GOV"               = "Office ProPlus"
  89.     "MCOSTANDARD_GOV"                      = "Lync Plan 2G"
  90.     "SHAREPOINTWAC_GOV"                    = "Office Online for Government"
  91.     "SHAREPOINTENTERPRISE_GOV"             = "SharePoint Plan 2G"
  92.     "EXCHANGE_S_ENTERPRISE_GOV"            = "Exchange Plan 2G"
  93.     "EXCHANGE_S_ARCHIVE_ADDON_GOV"         = "Exchange Online Archiving"
  94.     "EXCHANGE_S_DESKLESS"                  = "Exchange Online Kiosk"
  95.     "SHAREPOINTDESKLESS"                   = "SharePoint Online Kiosk"
  96.     "SHAREPOINTWAC"                        = "Office Online"
  97.     "YAMMER_ENTERPRISE"                    = "Yammer for the Starship Enterprise"
  98.     "EXCHANGE_L_STANDARD"                  = "Exchange Online (Plan 1)"
  99.     "MCOLITE"                              = "Lync Online (Plan 1)"
  100.     "SHAREPOINTLITE"                       = "SharePoint Online (Plan 1)"
  101.     "OFFICE_PRO_PLUS_SUBSCRIPTION_SMBIZ"   = "Office ProPlus"
  102.     "EXCHANGE_S_STANDARD_MIDMARKET"        = "Exchange Online (Plan 1)"
  103.     "MCOSTANDARD_MIDMARKET"                = "Lync Online (Plan 1)"
  104.     "SHAREPOINTENTERPRISE_MIDMARKET"       = "SharePoint Online (Plan 1)"
  105.     "OFFICESUBSCRIPTION"                   = "Office ProPlus"
  106.     "YAMMER_MIDSIZE"                       = "Yammer"
  107.     "DYN365_ENTERPRISE_PLAN1"              = "Dynamics 365 Customer Engagement Plan Enterprise Edition"
  108.     "ENTERPRISEPREMIUM_NOPSTNCONF"         = "Enterprise E5 (without Audio Conferencing)"
  109.     "ENTERPRISEPREMIUM"                    = "Enterprise E5 (with Audio Conferencing)"
  110.     "MCOSTANDARD"                          = "Skype for Business Online Standalone Plan 2"
  111.     "PROJECT_MADEIRA_PREVIEW_IW_SKU"       = "Dynamics 365 for Financials for IWs"
  112.     "STANDARDWOFFPACK_IW_STUDENT"          = "Office 365 Education for Students"
  113.     "STANDARDWOFFPACK_IW_FACULTY"          = "Office 365 Education for Faculty"
  114.     "EOP_ENTERPRISE_FACULTY"               = "Exchange Online Protection for Faculty"
  115.     "EXCHANGESTANDARD_STUDENT"             = "Exchange Online (Plan 1) for Students"
  116.     "OFFICESUBSCRIPTION_STUDENT"           = "Office ProPlus Student Benefit"
  117.     "STANDARDWOFFPACK_FACULTY"             = "Office 365 Education E1 for Faculty"
  118.     "STANDARDWOFFPACK_STUDENT"             = "Microsoft Office 365 (Plan A2) for Students"
  119.     "DYN365_FINANCIALS_BUSINESS_SKU"       = "Dynamics 365 for Financials Business Edition"
  120.     "DYN365_FINANCIALS_TEAM_MEMBERS_SKU"   = "Dynamics 365 for Team Members Business Edition"
  121.     "FLOW_FREE"                            = "Microsoft Flow Free"
  122.     "POWER_BI_PRO"                         = "Power BI Pro"
  123.     "O365_BUSINESS"                        = "Office 365 Business"
  124.     "DYN365_ENTERPRISE_SALES"              = "Dynamics Office 365 Enterprise Sales"
  125.     "RIGHTSMANAGEMENT"                     = "Rights Management"
  126.     "PROJECTPROFESSIONAL"                  = "Project Professional"
  127.     "VISIOONLINE_PLAN1"                    = "Visio Online Plan 1"
  128.     "EXCHANGEENTERPRISE"                   = "Exchange Online Plan 2"
  129.     "DYN365_ENTERPRISE_P1_IW"              = "Dynamics 365 P1 Trial for Information Workers"
  130.     "DYN365_ENTERPRISE_TEAM_MEMBERS"       = "Dynamics 365 For Team Members Enterprise Edition"
  131.     "CRMSTANDARD"                          = "Microsoft Dynamics CRM Online Professional"
  132.     "EXCHANGEARCHIVE_ADDON"                = "Exchange Online Archiving For Exchange Online"
  133.     "EXCHANGEDESKLESS"                     = "Exchange Online Kiosk"
  134.     "SPZA_IW"                              = "App Connect"
  135.     "WINDOWS_STORE"                        = "Windows Store for Business"
  136.     "MCOEV"                                = "Microsoft Phone System"
  137.     "VIDEO_INTEROP"                        = "Polycom Skype Meeting Video Interop for Skype for Business"
  138.     "SPE_E5"                               = "Microsoft 365 E5"
  139.     "SPE_E3"                               = "Microsoft 365 E3"
  140.     "ATA"                                  = "Advanced Threat Analytics"
  141.     "MCOPSTN2"                             = "Domestic and International Calling Plan"
  142.     "FLOW_P1"                              = "Microsoft Flow Plan 1"
  143.     "FLOW_P2"                              = "Microsoft Flow Plan 2"
  144. }
  145. # Get all users right away. Instead of doing several lookups, we will use this object to look up all the information needed.
  146. $AllUsers = get-azureaduser -All:$true
  147.  
  148. #Company Information
  149. $CompanyInfo = Get-AzureADTenantDetail
  150.  
  151.     $CompanyName = $CompanyInfo.DisplayName
  152.     $TechEmail = $CompanyInfo.TechnicalNotificationMails | Out-String
  153.     $DirSync = $CompanyInfo.DirSyncEnabled
  154.     $LastDirSync = $CompanyInfo.CompanyLastDirSyncTime
  155.    
  156.     # Can't find these in ADConnect module
  157.     # $LastPasswordSync = $CompanyInfo.LastPasswordSyncTime
  158.     # $PasswordSync = $CompanyInfo.PasswordSynchronizationEnabled
  159.     # $SelfServePassword = $CompanyInfo.SelfServePasswordResetEnabled
  160.  
  161.    
  162.     If ($DirSync -eq $False)
  163.     {
  164.         $LastDirSync = "Not Available"
  165.     }
  166.     If ($PasswordSync -eq $False)
  167.     {
  168.         $LastPasswordSync = "Not Available"
  169.     }
  170.    
  171.     $obj = New-Object -TypeName PSObject
  172.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $CompanyName
  173.     $obj | Add-Member -MemberType NoteProperty -Name "Technical Email" -Value $TechEmail
  174.     $obj | Add-Member -MemberType NoteProperty -Name "Directory Sync" -value $DirSync
  175.     $obj | Add-Member -MemberType NoteProperty -Name "Last Directory Sync" -value $LastDirSync
  176.    
  177.     # Can't find these in ADConnect module
  178.     # $obj | Add-Member -MemberType NoteProperty -Name "Self Service Password Reset" -value $SelfServePassword
  179.     # $obj | Add-Member -MemberType NoteProperty -Name "Password Sync" -value $PasswordSync
  180.     # $obj | Add-Member -MemberType NoteProperty -Name "Last Password Sync" -value $LastPasswordSync
  181.  
  182.     $CompanyInfoTable.add($obj)
  183.  
  184. #Get Tenant Global Admins
  185. $role = Get-AzureADDirectoryRole | where {$_.DisplayName -match "Company Administrator"}
  186. $Admins = Get-AzureADDirectoryRoleMember -ObjectId $role.ObjectId
  187. Foreach ($Admin in $Admins)
  188. {
  189.     $Name = $Admin.DisplayName
  190.     # IsLicensed is a MSOnline property only. Using assignedlicenses instead
  191.     # $Licensed = $Admin.IsLicensed
  192.     $EmailAddress = $Admin.Mail
  193.     if($admins.assignedlicenses)
  194.         {$Licensed = $true}
  195.         else{$Licensed = $false}
  196.    
  197.     $obj = New-Object -TypeName PSObject
  198.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $Name
  199.     $obj | Add-Member -MemberType NoteProperty -Name "Is Licensed" -value $Licensed
  200.     $obj | Add-Member -MemberType NoteProperty -Name "E-Mail Address" -value $EmailAddress
  201.    
  202.     $GlobalAdminTable.add($obj)
  203. }
  204.  
  205.  
  206.  
  207. #Users with Strong Password Requirements disabled
  208. $LooseUsers = $AllUsers | Where-Object {$_.StrongPasswordRequired -eq $False}
  209. Foreach ($LooseUser in $LooseUsers)
  210. {
  211.     $NameLoose = $LooseUser.DisplayName
  212.     $UPNLoose = $LooseUser.UserPrincipalName
  213.     $StrongPasswordLoose = $LooseUser.StrongPasswordRequired
  214.     # IsLicensed is a MSOnline property only. Using assignedlicenses instead
  215.     # $LicensedLoose = $LooseUser.IsLicensed
  216.     if($LooseUser.assignedlicenses)
  217.         {$LicensedLoose = $true}
  218.         else{$LicensedLoose = $false}  
  219.  
  220.     $obj = New-Object -TypeName PSObject
  221.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $NameLoose
  222.     $obj | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $UPNLoose
  223.     $obj | Add-Member -MemberType NoteProperty -Name "Is Licensed" -value $LicensedLoose
  224.     $obj | Add-Member -MemberType NoteProperty -Name "Strong Password Required" -value $StrongPasswordLoose
  225.    
  226.     $StrongPasswordTable.add($obj)
  227. }
  228.  
  229. #Message Trace / Recent Messages
  230. $RecentMessages = Get-MessageTrace
  231. Foreach ($RecentMessage in $RecentMessages)
  232. {
  233.     $TraceDate = $RecentMessage.Received
  234.     $Sender = $RecentMessage.SenderAddress
  235.     $Recipient = $RecentMessage.RecipientAddress
  236.     $Subject = $RecentMessage.Subject
  237.     $Status = $RecentMessage.Status
  238.    
  239.     $obj = New-Object -TypeName PSObject
  240.     $obj | Add-Member -MemberType NoteProperty -Name "Received Date" -Value $TraceDate
  241.     $obj | Add-Member -MemberType NoteProperty -Name "E-Mail Subject" -Value $Subject
  242.     $obj | Add-Member -MemberType NoteProperty -Name "Sender" -Value $Sender
  243.     $obj | Add-Member -MemberType NoteProperty -Name "Recipient" -value $Recipient
  244.     $obj | Add-Member -MemberType NoteProperty -Name "Status" -value $Status
  245.    
  246.     $MessageTraceTable.add($obj)
  247. }
  248.  
  249. #Tenant Domain
  250. $Domains = Get-AzureAdDomain
  251. foreach ($Domain in $Domains)
  252. {
  253.     $DomainName = $Domain.Name
  254.     $Verified = $Domain.IsVerified
  255.     $DefaultStatus = $Domain.IsDefault
  256.  
  257.     $obj = New-Object -TypeName PSObject
  258.     $obj | Add-Member -MemberType NoteProperty -Name "Domain Name" -Value $DomainName
  259.     $obj | Add-Member -MemberType NoteProperty -Name "Verification Status" -Value $Verified
  260.     $obj | Add-Member -MemberType NoteProperty -Name "Default" -Value $DefaultStatus
  261.  
  262.    
  263.     $DomainTable.add($obj)
  264. }
  265.  
  266.  
  267. #Get groups and sort in alphabetical order
  268. $Groups = Get-AzureAdGroup -All | Sort-Object DisplayName
  269. $DistroCount = ($Groups | Where-Object { $_.MailEnabled -eq $true -and $_.SecurityEnabled -eq $false }).Count
  270. $obj1 = New-Object -TypeName PSObject
  271. $obj1 | Add-Member -MemberType NoteProperty -Name Name -Value "Distribution Group"
  272. $obj1 | Add-Member -MemberType NoteProperty -Name Count -Value $DistroCount
  273.  
  274. $GroupTypetable.add($obj1)
  275.  
  276. $SecurityCount = ($Groups | Where-Object { $_.MailEnabled -eq $false -and $_.SecurityEnabled -eq $true }).Count
  277. $obj1 = New-Object -TypeName PSObject
  278. $obj1 | Add-Member -MemberType NoteProperty -Name Name -Value "Security Group"
  279. $obj1 | Add-Member -MemberType NoteProperty -Name Count -Value $SecurityCount
  280.  
  281. $GroupTypetable.add($obj1)
  282.  
  283. $SecurityMailEnabledCount = ($Groups | Where-Object { $_.MailEnabled -eq $true -and $_.SecurityEnabled -eq $true }).Count
  284. $obj1 = New-Object -TypeName PSObject
  285. $obj1 | Add-Member -MemberType NoteProperty -Name Name -Value "Mail Enabled Security Group"
  286. $obj1 | Add-Member -MemberType NoteProperty -Name Count -Value $SecurityMailEnabledCount
  287.  
  288. $GroupTypetable.add($obj1)
  289.  
  290. Foreach ($Group in $Groups)
  291. {
  292.     if($group.MailEnabled -eq $true -and $group.SecurityEnabled -eq $false){$Type = "Distribution Group"}
  293.     if($group.MailEnabled -eq $false -and $group.SecurityEnabled -eq $true){$Type = "Security Group"}
  294.     if($group.MailEnabled -eq $true -and $group.SecurityEnabled -eq $true){$Type = "Mail Enabled Security Group"}
  295.  
  296.     $Users = (Get-AzureADGroupMember -ObjectId $Group.ObjectID | Sort-Object DisplayName | Select-Object -ExpandProperty DisplayName) -join ", "
  297.     $GName = $Group.DisplayName
  298.    
  299.     $hash = New-Object PSObject -property @{ Name = "$GName"; Type = "$Type"; Members = "$Users" }
  300.     $GEmail = $Group.Mail
  301.    
  302.    
  303.     $obj = New-Object -TypeName PSObject
  304.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $GName
  305.     $obj | Add-Member -MemberType NoteProperty -Name Type -Value $Type
  306.     $obj | Add-Member -MemberType NoteProperty -Name Members -value $users
  307.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Address" -value $GEmail
  308.    
  309.     $table.add($obj)
  310. }
  311.  
  312. #Get all licenses
  313. $Licenses = Get-AzureADSubscribedSku
  314. #Split licenses at colon
  315. Foreach ($License in $Licenses)
  316. {
  317. $TextLic = $null
  318.      
  319.     $ASku = ($License).SkuPartNumber
  320.     $TextLic = $Sku.Item("$ASku")
  321.     If (!($TextLic))
  322.     {
  323.         $OLicense = $License.SkuPartNumber
  324.     }
  325.     Else
  326.     {
  327.         $OLicense = $TextLic
  328.     }
  329.    
  330.     $TotalAmount = $License.PrepaidUnits.enabled
  331.     $Assigned = $License.ConsumedUnits
  332.     $Unassigned = ($TotalAmount - $Assigned)
  333.     If ($TotalAmount -lt 1000)
  334.     {
  335.        
  336.         $obj = New-Object -TypeName PSObject
  337.         $obj | Add-Member -MemberType NoteProperty -Name Name -Value $Olicense
  338.         $obj | Add-Member -MemberType NoteProperty -Name "Total Amount" -Value $TotalAmount
  339.         $obj | Add-Member -MemberType NoteProperty -Name "Assigned Licenses" -value $Assigned
  340.         $obj | Add-Member -MemberType NoteProperty -Name "Unassigned Licenses" -value $Unassigned
  341.        
  342.         $licensetable.add($obj)
  343.     }
  344. }
  345.  
  346.  
  347. #$user = get-msoluser | Where-Object {$_.DisplayName -like "*Brad Wyatt*"}
  348.    
  349. $IsLicensed = ($AllUsers | Where-Object { $_.assignedlicenses.count -gt 0 }).Count
  350. $objULic = New-Object -TypeName PSObject
  351. $objULic | Add-Member -MemberType NoteProperty -Name Name -Value "Users Licensed"
  352. $objULic | Add-Member -MemberType NoteProperty -Name Count -Value $IsLicensed
  353.  
  354. $IsLicensedUsersTable.add($objULic)
  355.  
  356. $ISNotLicensed = ($AllUsers | Where-Object { $_.assignedlicenses.count -eq 0 }).Count
  357. $objULic = New-Object -TypeName PSObject
  358. $objULic | Add-Member -MemberType NoteProperty -Name Name -Value "Users Not Licensed"
  359. $objULic | Add-Member -MemberType NoteProperty -Name Count -Value $IsNotLicensed
  360.  
  361. $IsLicensedUsersTable.add($objULic)
  362.  
  363.  
  364. Foreach ($User in $AllUsers)
  365. {
  366.     $ProxyA = New-Object 'System.Collections.Generic.List[System.Object]'
  367.     $NewObject02 = New-Object 'System.Collections.Generic.List[System.Object]'
  368.     $NewObject01 = New-Object 'System.Collections.Generic.List[System.Object]'
  369.     $UserLicenses = ($User | Select-Object -ExpandProperty AssignedLicenses).SkuId
  370.     If (($UserLicenses).count -gt 1)
  371.     {
  372.         Foreach ($UserLicense in $UserLicenses)
  373.         {
  374.             $lic = ($licenses | where {$_.skuid -match ($user | Select-Object -ExpandProperty assignedLicenses).skuid}).SkuPartNumber
  375.             $TextLic = $Sku.Item("$lic")
  376.             If (!($TextLic))
  377.             {
  378.                 $NewObject01 = New-Object PSObject
  379.                 $NewObject01 | Add-Member -MemberType NoteProperty -Name "Licenses" -Value $lic
  380.                 $NewObject02.add($NewObject01)
  381.             }
  382.             Else
  383.             {
  384.                 $NewObject01 = New-Object PSObject
  385.                 $NewObject01 | Add-Member -MemberType NoteProperty -Name "Licenses" -Value $textlic
  386.                 $NewObject02.add($NewObject01)
  387.             }
  388.            
  389.         }
  390.     }
  391.     Else
  392.     {
  393.         $lic = ($licenses | where {$_.skuid -match ($user | Select-Object -ExpandProperty assignedLicenses).skuid}).SkuPartNumber
  394.         $TextLic = $Sku.Item("$lic")
  395.         If (!($TextLic))
  396.         {
  397.             $NewObject01 = New-Object PSObject
  398.             $NewObject01 | Add-Member -MemberType NoteProperty -Name "Licenses" -Value $lic
  399.             $NewObject02.add($NewObject01)
  400.         }
  401.         Else
  402.         {
  403.             $NewObject01 = New-Object PSObject
  404.             $NewObject01 | Add-Member -MemberType NoteProperty -Name "Licenses" -Value $textlic
  405.             $NewObject02.add($NewObject01)
  406.         }
  407.     }
  408.    
  409.     $ProxyAddresses = ($User | Select-Object -ExpandProperty ProxyAddresses)
  410.     If ($ProxyAddresses -ne $Null)
  411.     {
  412.         Foreach ($Proxy in $ProxyAddresses)
  413.         {
  414.             $ProxyB = $Proxy -split ":" | Select-Object -Last 1
  415.             $ProxyA.add($ProxyB)
  416.            
  417.         }
  418.         $ProxyC = $ProxyA -join ", "
  419.     }
  420.     Else
  421.     {
  422.         $ProxyC = $Null
  423.     }
  424.    
  425.     $Name = $User.DisplayName
  426.     $UPN = $User.UserPrincipalName
  427.     $UserLicenses = ($NewObject02 | Select-Object -ExpandProperty Licenses) -join ", "
  428.     $Enabled = $User.AccountEnabled
  429.     $LastLogonUser = (Get-Mailbox -Identity $User.DisplayName -ErrorAction SilentlyContinue | Get-MailboxStatistics -ErrorAction SilentlyContinue).LastLogonTime
  430.  
  431.  
  432.     $obj = New-Object -TypeName PSObject
  433.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $Name
  434.     $obj | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $UPN
  435.     $obj | Add-Member -MemberType NoteProperty -Name Licenses -value $UserLicenses
  436.     $obj | Add-Member -MemberType NoteProperty -Name "Last Logon" -value $LastLogonUser
  437.     $obj | Add-Member -MemberType NoteProperty -Name Enabled -value $Enabled
  438.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Addresses" -value $ProxyC
  439.    
  440.     $usertable.add($obj)
  441. }
  442.  
  443. #Get all Shared Mailboxes
  444. $SharedMailboxes = Get-Recipient -Resultsize unlimited | Where-Object { $_.RecipientTypeDetails -eq "SharedMailbox" }
  445. Foreach ($SharedMailbox in $SharedMailboxes)
  446. {
  447.     $ProxyA = New-Object 'System.Collections.Generic.List[System.Object]'
  448.     $Name = $SharedMailbox.Name
  449.     $PrimEmail = $SharedMailbox.PrimarySmtpAddress
  450.     $ProxyAddresses = ($SharedMailbox | Where-Object { $_.EmailAddresses -notlike "*$PrimEmail*" } | Select-Object -ExpandProperty EmailAddresses)
  451.     If ($ProxyAddresses -ne $Null)
  452.     {
  453.         Foreach ($ProxyAddress in $ProxyAddresses)
  454.         {
  455.             $ProxyB = $ProxyAddress -split ":" | Select-Object -Last 1
  456.             If ($ProxyB -eq $PrimEmail)
  457.             {
  458.                 $ProxyB = $Null
  459.             }
  460.             $ProxyA.add($ProxyB)
  461.             $ProxyC = $ProxyA
  462.         }
  463.     }
  464.     Else
  465.     {
  466.         $ProxyC = $Null
  467.     }
  468.    
  469.     $ProxyF = ($ProxyC -join ", ").TrimEnd(", ")
  470.    
  471.     $obj = New-Object -TypeName PSObject
  472.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $Name
  473.     $obj | Add-Member -MemberType NoteProperty -Name "Primary E-Mail" -Value $PrimEmail
  474.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Addresses" -value $ProxyF
  475.    
  476.     $SharedMailboxTable.add($obj)
  477.    
  478. }
  479.  
  480. #Get all Contacts
  481. $Contacts = Get-MailContact
  482. #Split licenses at colon
  483. Foreach ($Contact in $Contacts)
  484. {
  485.    
  486.     $ContactName = $Contact.DisplayName
  487.     $ContactPrimEmail = $Contact.PrimarySmtpAddress
  488.    
  489.    
  490.     $objContact = New-Object -TypeName PSObject
  491.     $objContact | Add-Member -MemberType NoteProperty -Name Name -Value $ContactName
  492.     $objContact | Add-Member -MemberType NoteProperty -Name "E-mail Address" -Value $ContactPrimEmail
  493.    
  494.     $ContactTable.add($objContact)
  495.    
  496. }
  497.  
  498. #Get all Mail Users
  499. $MailUsers = Get-MailUser
  500. foreach ($MailUser in $mailUsers)
  501. {
  502.     $MailArray = New-Object 'System.Collections.Generic.List[System.Object]'
  503.     $MailPrimEmail = $MailUser.PrimarySmtpAddress
  504.     $MailName = $MailUser.DisplayName
  505.     $MailEmailAddresses = ($MailUser.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' })
  506.     foreach ($MailEmailAddress in $MailEmailAddresses)
  507.     {
  508.         $MailEmailAddressSplit = $MailEmailAddress -split ":" | Select-Object -Last 1
  509.         $MailArray.add($MailEmailAddressSplit)
  510.        
  511.        
  512.     }
  513.    
  514.     $UserEmails = $MailArray -join ", "
  515.    
  516.     $obj = New-Object -TypeName PSObject
  517.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $MailName
  518.     $obj | Add-Member -MemberType NoteProperty -Name "Primary E-Mail" -Value $MailPrimEmail
  519.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Addresses" -value $UserEmails
  520.    
  521.     $ContactMailUserTable.add($obj)
  522. }
  523.  
  524. $Rooms = Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")'
  525. Foreach ($Room in $Rooms)
  526. {
  527.     $RoomArray = New-Object 'System.Collections.Generic.List[System.Object]'
  528.  
  529.     $RoomName = $Room.DisplayName
  530.     $RoomPrimEmail = $Room.PrimarySmtpAddress
  531.     $RoomEmails = ($Room.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' })
  532.     foreach ($RoomEmail in $RoomEmails)
  533.         {
  534.             $RoomEmailSplit = $RoomEmail -split ":" | Select-Object -Last 1
  535.             $RoomArray.add($RoomEmailSplit)
  536.         }
  537.     $RoomEMailsF = $RoomArray -join ", "
  538.  
  539.     $obj = New-Object -TypeName PSObject
  540.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $RoomName
  541.     $obj | Add-Member -MemberType NoteProperty -Name "Primary E-Mail" -Value $RoomPrimEmail
  542.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Addresses" -value $RoomEmailsF
  543.    
  544.     $RoomTable.add($obj)
  545. }
  546.  
  547. $EquipMailboxes = Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailBox")'
  548. Foreach ($EquipMailbox in $EquipMailboxes)
  549. {
  550.     $EquipArray = New-Object 'System.Collections.Generic.List[System.Object]'
  551.  
  552.     $EquipName = $EquipMailbox.DisplayName
  553.     $EquipPrimEmail = $EquipMailbox.PrimarySmtpAddress
  554.     $EquipEmails = ($EquipMailbox.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' })
  555.     foreach ($EquipEmail in $EquipEmails)
  556.         {
  557.             $EquipEmailSplit = $EquipEmail -split ":" | Select-Object -Last 1
  558.             $EquipArray.add($EquipEmailSplit)
  559.         }
  560.     $EquipEMailsF = $EquipArray -join ", "
  561.  
  562.     $obj = New-Object -TypeName PSObject
  563.     $obj | Add-Member -MemberType NoteProperty -Name Name -Value $EquipName
  564.     $obj | Add-Member -MemberType NoteProperty -Name "Primary E-Mail" -Value $EquipPrimEmail
  565.     $obj | Add-Member -MemberType NoteProperty -Name "E-mail Addresses" -value $EquipEmailsF
  566.    
  567.     $EquipTable.add($obj)
  568. }
  569.  
  570.  
  571. $tabarray = @('Dashboard','Groups', 'Licenses', 'Users', 'Shared Mailboxes', 'Contacts', 'Resources')
  572.  
  573. #basic Properties
  574. $PieObject2 = Get-HTMLPieChartObject
  575. $PieObject2.Title = "Office 365 Total Licenses"
  576. $PieObject2.Size.Height = 250
  577. $PieObject2.Size.width = 250
  578. $PieObject2.ChartStyle.ChartType = 'doughnut'
  579.  
  580. #These file exist in the module directoy, There are 4 schemes by default
  581. $PieObject2.ChartStyle.ColorSchemeName = "ColorScheme4"
  582. #There are 8 generated schemes, randomly generated at runtime
  583. $PieObject2.ChartStyle.ColorSchemeName = "Generated7"
  584. #you can also ask for a random scheme.  Which also happens if you have too many records for the scheme
  585. $PieObject2.ChartStyle.ColorSchemeName = 'Random'
  586.  
  587. #Data defintion you can reference any column from name and value from the  dataset.  
  588. #Name and Count are the default to work with the Group function.
  589. $PieObject2.DataDefinition.DataNameColumnName = 'Name'
  590. $PieObject2.DataDefinition.DataValueColumnName = 'Total Amount'
  591.  
  592. #basic Properties
  593. $PieObject3 = Get-HTMLPieChartObject
  594. $PieObject3.Title = "Office 365 Assigned Licenses"
  595. $PieObject3.Size.Height = 250
  596. $PieObject3.Size.width = 250
  597. $PieObject3.ChartStyle.ChartType = 'doughnut'
  598.  
  599. #These file exist in the module directoy, There are 4 schemes by default
  600. $PieObject3.ChartStyle.ColorSchemeName = "ColorScheme4"
  601. #There are 8 generated schemes, randomly generated at runtime
  602. $PieObject3.ChartStyle.ColorSchemeName = "Generated5"
  603. #you can also ask for a random scheme.  Which also happens if you have too many records for the scheme
  604. $PieObject3.ChartStyle.ColorSchemeName = 'Random'
  605.  
  606. #Data defintion you can reference any column from name and value from the  dataset.  
  607. #Name and Count are the default to work with the Group function.
  608. $PieObject3.DataDefinition.DataNameColumnName = 'Name'
  609. $PieObject3.DataDefinition.DataValueColumnName = 'Assigned Licenses'
  610.  
  611. #basic Properties
  612. $PieObject4 = Get-HTMLPieChartObject
  613. $PieObject4.Title = "Office 365 Unassigned Licenses"
  614. $PieObject4.Size.Height = 250
  615. $PieObject4.Size.width = 250
  616. $PieObject4.ChartStyle.ChartType = 'doughnut'
  617.  
  618. #These file exist in the module directoy, There are 4 schemes by default
  619. $PieObject4.ChartStyle.ColorSchemeName = "ColorScheme4"
  620. #There are 8 generated schemes, randomly generated at runtime
  621. $PieObject4.ChartStyle.ColorSchemeName = "Generated4"
  622. #you can also ask for a random scheme.  Which also happens if you have too many records for the scheme
  623. $PieObject4.ChartStyle.ColorSchemeName = 'Random'
  624.  
  625. #Data defintion you can reference any column from name and value from the  dataset.  
  626. #Name and Count are the default to work with the Group function.
  627. $PieObject4.DataDefinition.DataNameColumnName = 'Name'
  628. $PieObject4.DataDefinition.DataValueColumnName = 'Unassigned Licenses'
  629.  
  630. #basic Properties
  631. $PieObjectGroupType = Get-HTMLPieChartObject
  632. $PieObjectGroupType.Title = "Office 365 Groups"
  633. $PieObjectGroupType.Size.Height = 250
  634. $PieObjectGroupType.Size.width = 250
  635. $PieObjectGroupType.ChartStyle.ChartType = 'doughnut'
  636.  
  637. #These file exist in the module directoy, There are 4 schemes by default
  638. $PieObjectGroupType.ChartStyle.ColorSchemeName = "ColorScheme4"
  639. #There are 8 generated schemes, randomly generated at runtime
  640. $PieObjectGroupType.ChartStyle.ColorSchemeName = "Generated8"
  641. #you can also ask for a random scheme.  Which also happens if you have too many records for the scheme
  642. $PieObjectGroupType.ChartStyle.ColorSchemeName = 'Random'
  643.  
  644. #Data defintion you can reference any column from name and value from the  dataset.  
  645. #Name and Count are the default to work with the Group function.
  646. $PieObjectGroupType.DataDefinition.DataNameColumnName = 'Name'
  647. $PieObjectGroupType.DataDefinition.DataValueColumnName = 'Count'
  648.  
  649. ##--LICENSED AND UNLICENSED USERS PIE CHART--##
  650. #basic Properties
  651. $PieObjectULicense = Get-HTMLPieChartObject
  652. $PieObjectULicense.Title = "License Status"
  653. $PieObjectULicense.Size.Height = 250
  654. $PieObjectULicense.Size.width = 250
  655. $PieObjectULicense.ChartStyle.ChartType = 'doughnut'
  656.  
  657. #These file exist in the module directoy, There are 4 schemes by default
  658. $PieObjectULicense.ChartStyle.ColorSchemeName = "ColorScheme3"
  659. #There are 8 generated schemes, randomly generated at runtime
  660. $PieObjectULicense.ChartStyle.ColorSchemeName = "Generated3"
  661. #you can also ask for a random scheme.  Which also happens if you have too many records for the scheme
  662. $PieObjectULicense.ChartStyle.ColorSchemeName = 'Random'
  663.  
  664. #Data defintion you can reference any column from name and value from the  dataset.  
  665. #Name and Count are the default to work with the Group function.
  666. $PieObjectULicense.DataDefinition.DataNameColumnName = 'Name'
  667. $PieObjectULicense.DataDefinition.DataValueColumnName = 'Count'
  668.  
  669. $rpt = @()
  670. $rpt += get-htmlopenpage -TitleText 'Office 365 Tenant Report' -LeftLogoString $CompanyLogo -RightLogoString $RightLogo
  671.  
  672. $rpt += Get-HTMLTabHeader -TabNames $tabarray
  673.     $rpt += get-htmltabcontentopen -TabName $tabarray[0] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  674.         $rpt+= Get-HtmlContentOpen -HeaderText "Office 365 Dashboard"
  675.           $rpt += Get-HTMLContentOpen -HeaderText "Company Information"
  676.             $rpt += Get-HtmlContentTable $CompanyInfoTable
  677.           $rpt += Get-HTMLContentClose
  678.  
  679.             $rpt+= get-HtmlColumn1of2
  680.                 $rpt+= Get-HtmlContentOpen -BackgroundShade 1 -HeaderText 'Global Administrators'
  681.                     $rpt+= get-htmlcontentdatatable  $GlobalAdminTable -HideFooter
  682.                 $rpt+= Get-HtmlContentClose
  683.             $rpt+= get-htmlColumnClose
  684.                 $rpt+= get-htmlColumn2of2
  685.                     $rpt+= Get-HtmlContentOpen -HeaderText 'Users With Strong Password Enforcement Disabled'
  686.                         $rpt+= get-htmlcontentdatatable  $StrongPasswordTable -HideFooter
  687.                 $rpt+= Get-HtmlContentClose
  688.             $rpt+= get-htmlColumnClose
  689.  
  690.           $rpt += Get-HTMLContentOpen -HeaderText "Recent E-Mails"
  691.             $rpt += Get-HTMLContentDataTable $MessageTraceTable -HideFooter
  692.           $rpt += Get-HTMLContentClose
  693.  
  694.           $rpt += Get-HTMLContentOpen -HeaderText "Domains"
  695.             $rpt += Get-HtmlContentTable $DomainTable
  696.           $rpt += Get-HTMLContentClose
  697.  
  698.         $rpt+= Get-HtmlContentClose
  699.     $rpt += get-htmltabcontentclose
  700.  
  701.     $rpt += get-htmltabcontentopen -TabName $tabarray[1] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  702.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Groups"
  703.             $rpt += get-htmlcontentdatatable $Table -HideFooter
  704.         $rpt += Get-HTMLContentClose
  705.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Groups Chart"
  706.             $rpt += Get-HTMLPieChart -ChartObject $PieObjectGroupType -DataSet $GroupTypetable
  707.         $rpt += Get-HTMLContentClose
  708.     $rpt += get-htmltabcontentclose
  709.     $rpt += get-htmltabcontentopen -TabName $tabarray[2]  -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  710.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Licenses"
  711.             $rpt += get-htmlcontentdatatable $LicenseTable -HideFooter
  712.         $rpt += Get-HTMLContentClose
  713.     $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Licensing Charts"
  714.         $rpt += Get-HTMLColumnOpen -ColumnNumber 1 -ColumnCount 2
  715.             $rpt += Get-HTMLPieChart -ChartObject $PieObject2 -DataSet $licensetable
  716.         $rpt += Get-HTMLColumnClose
  717.         $rpt += Get-HTMLColumnOpen -ColumnNumber 2 -ColumnCount 2
  718.             $rpt += Get-HTMLPieChart -ChartObject $PieObject3 -DataSet $licensetable
  719.         $rpt += Get-HTMLColumnClose
  720.     $rpt += Get-HTMLContentclose
  721.     $rpt += get-htmltabcontentclose
  722.     $rpt += get-htmltabcontentopen -TabName $tabarray[3] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  723.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Users"
  724.             $rpt += get-htmlcontentdatatable $UserTable -HideFooter
  725.         $rpt += Get-HTMLContentClose
  726.         $rpt += Get-HTMLContentOpen -HeaderText "Licensed & Unlicensed Users Chart"
  727.             $rpt += Get-HTMLPieChart -ChartObject $PieObjectULicense -DataSet $IsLicensedUsersTable
  728.         $rpt += Get-HTMLContentClose
  729.     $rpt += get-htmltabcontentclose
  730.     $rpt += get-htmltabcontentopen -TabName $tabarray[4] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  731.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Shared Mailboxes"
  732.         $rpt += get-htmlcontentdatatable $SharedMailboxTable -HideFooter
  733.         $rpt += Get-HTMLContentClose
  734.     $rpt += get-htmltabcontentclose
  735.         $rpt += get-htmltabcontentopen -TabName $tabarray[5] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  736.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Contacts"
  737.             $rpt += get-htmlcontentdatatable $ContactTable -HideFooter
  738.         $rpt += Get-HTMLContentClose
  739.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Mail Users"
  740.             $rpt += get-htmlcontentdatatable $ContactMailUserTable -HideFooter
  741.         $rpt += Get-HTMLContentClose
  742.     $rpt += get-htmltabcontentclose
  743.     $rpt += get-htmltabcontentopen -TabName $tabarray[6] -TabHeading ("Report: " + (Get-Date -Format MM-dd-yyyy))
  744.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Room Mailboxes"
  745.             $rpt += get-htmlcontentdatatable $RoomTable -HideFooter
  746.         $rpt += Get-HTMLContentClose
  747.         $rpt += Get-HTMLContentOpen -HeaderText "Office 365 Equipment Mailboxes"
  748.             $rpt += get-htmlcontentdatatable $EquipTable -HideFooter
  749.         $rpt += Get-HTMLContentClose
  750.     $rpt += get-htmltabcontentclose
  751.  
  752. $rpt += Get-HTMLClosePage
  753.  
  754. $Day = (Get-Date).Day
  755. $Month = (Get-Date).Month
  756. $Year = (Get-Date).Year
  757. $ReportName = ("$Day" + "-" + "$Month" + "-" + "$Year" + "-" + "O365 Tenant Report")
  758. Save-HTMLReport -ReportContent $rpt -ShowReport -ReportName $ReportName -ReportPath $ReportSavePath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement