Đối tượng Excel COM PowerShell

Tôi bắt đầu khám phá một cách để tạo một báo cáo Office 365 đẹp, nhiều trang mà tôi có thể cung cấp cho người dùng cuối hoặc Người quản lý Office bằng cách sử dụng PowerShell. Thật không may, tôi đã đọc về giao diện COM của Excel trước khi đọc về mô-đun Excel PowerShell do Doug Finke tạo ra. Nếu bạn đang bắt đầu từ đầu, tôi khuyên bạn nên đọc Mô-đun PowerShell thay vì đi theo lộ trình COM vì Giao diện COM của Excel sẽ dễ sử dụng hơn. Bất chấp điều đó, tôi đã hoàn thành tập lệnh PowerShell của mình và muốn chia sẻ nó cho những người khác sử dụng

điều kiện tiên quyết

Không có nhiều yêu cầu trước cho tập lệnh này và tôi đã thiết kế nó theo cách đó. Lúc đầu, nó phụ thuộc vào Sổ làm việc Excel được định dạng sẵn theo cách tôi thích và nó sẽ chỉ điền dữ liệu dành riêng cho sổ làm việc đó. Tuy nhiên, tôi đã quyết định định dạng PowerShell Sổ làm việc Excel từ đầu khi nó chạy. Vì vậy, để tập lệnh này chạy, bạn chỉ cần 1 điều. (Tôi nghĩ không cần phải nói, nhưng bạn cũng sẽ cần PowerShell cũng như tài khoản Office 365)

  • Excel

Báo cáo mục tiêu

Đối với báo cáo của tôi, tôi muốn đảm bảo rằng nó có thể thực hiện ít nhất những điều sau

  1. Tạo một WorkSheet riêng cho từng báo cáo
  2. Mỗi WorkSheet sẽ có một tiêu đề đẹp, rõ ràng
  3. Báo cáo sau
    1. Hộp thư được cấp phép
      1. Người dùng có giấy phép
      2. Tên hiển thị
      3. Tên giấy phép thân thiện
        1. Nếu không tìm thấy tên thân thiện, chỉ cần sử dụng AccountSkuID
      4. Địa chỉ email chính
      5. Địa chỉ email bí danh
    2. Các nhóm
      1. Tên nhóm
      2. Loại nhóm
        1. Phân bổ
        2. Nhóm văn phòng 365
        3. Nhóm bảo mật
        4. vân vân…
      3. Địa chỉ E-Mail Nhóm (nếu có một. )
    3. Hộp thư chung
      1. Tên hộp thư dùng chung
      2. Địa chỉ email
    4. Liên lạc
      1. Tên
      2. Địa chỉ email
    5. thư mục công cộng
      1. Tên
      2. Nếu nó được kích hoạt qua thư
      3. Địa chỉ email
    6. tên miền
      1. Tên miền
      2. Nếu nó được xác minh đầy đủ
      3. Nếu nó mặc định
        1. Nếu nó là mặc định, hãy đánh dấu nó
  4. Làm cho báo cáo đẹp mắt và dễ đọc
  5. Hiển thị dữ liệu theo thứ tự bảng chữ cái
  6. Tự động định dạng hàng và cột Excel

Định dạng báo cáo

Bên dưới, bạn có thể thấy một số tab khác nhau của báo cáo từ khi tôi chạy nó trên đối tượng thuê Office 365 thử nghiệm của mình

Đối tượng Excel COM PowerShell
Báo cáo về tất cả các Nhóm trong đối tượng thuê của tôi
Đối tượng Excel COM PowerShell
Báo cáo Thư mục công cộng, hiển thị Tên, E-Mail và nếu đó là Thư được kích hoạt
Đối tượng Excel COM PowerShell
Người dùng được cấp phép,

Mỗi báo cáo sẽ được chứa trong Bảng tính Excel của riêng nó. Ô A1. C1 sẽ chứa tên báo cáo và hàng 2 sẽ chứa tiêu đề báo cáo. Như chúng ta thấy trong hình, các ô tiêu đề và các ô số được định dạng với nền màu xanh lam và chữ màu trắng để nổi bật so với kết quả báo cáo. Đối với báo cáo Người dùng được cấp phép, nó sẽ lấy SKU của giấy phép (hoặc SKU của nếu bạn có nhiều hơn 1 giấy phép) và chuyển đổi SKU thành tên giấy phép thân thiện bằng cách sử dụng Bảng băm. Nếu không thể tìm thấy kết quả phù hợp, nó sẽ không hoạt động trở lại trên AccountSkuID. Vì vậy, nếu nó không thể tìm thấy giấy phép Gói doanh nghiệp E1 trong Bảng băm, nó sẽ liệt kê “EXCHANGESTANDARD”

PowerShell sẽ tạo toàn bộ Sổ làm việc Excel, tất cả các Bảng tính báo cáo và định dạng trang tính từ đầu khi chuyển từ báo cáo này sang báo cáo khác. Video dưới đây cho thấy tôi đang chạy tập lệnh. PowerShell gọi đối tượng Excel COM bằng cách chạy

$excel = New-Object -ComObject Excel.Application

 

Và sau đó nó sẽ hiển thị chương trình Excel bằng cách chạy

$excel.Visible = $true

 

Khi dữ liệu bắt đầu điền vào báo cáo, nó sẽ liên tục tự động điều chỉnh kích thước các hàng và cột để tất cả dữ liệu vừa vặn với từng ô. Màu nền của dữ liệu báo cáo sẽ thay đổi từ trắng sang xám nhạt. Khi hoàn thành báo cáo, nó sẽ tự động chuyển sang trang tính tiếp theo. Điều này sẽ giúp bạn xem những gì nó đang hoạt động nếu bạn chọn mở ứng dụng Excel trong khi nó chạy

Trong hình bên dưới, chúng ta có thể thấy nó thay đổi thành trang tính Hộp thư được cấp phép. Ô 1,1 trở thành tiêu đề báo cáo, sau đó nó sẽ thay đổi thành cỡ chữ 26, phông chữ thay đổi thành Cambria, thay đổi màu phông chữ và căn chỉnh rồi hợp nhất các ô a1,c1

Đối tượng Excel COM PowerShell

Khi nó kết thúc với tiêu đề báo cáo, nó sẽ bắt đầu với tiêu đề báo cáo. Cái đầu tiên nó tạo là “#” sẽ gắn nhãn các hàng trong báo cáo. Tất cả các tiêu đề sẽ được định dạng theo cùng một cách

Báo cáo dữ liệu

Hộp thư được cấp phép

Đối tượng Excel COM PowerShell

Báo cáo “Hộp thư được cấp phép” sẽ hiển thị cho bạn thông tin sau

  • Tên tài khoản người dùng
  • Tên giấy phép Office 365 thân thiện
  • Địa chỉ email chính
  • Tất cả các địa chỉ E-Mail bí danh

Báo cáo hộp thư giấy phép sẽ tra cứu từng giấy phép người dùng được lưu trữ ở định dạng như “{bwya77. FLOW_FREE, bwya77. TIÊU CHUẨN TRAO ĐỔI}”. Nó sẽ đi qua từng giấy phép và tra cứu tên thân thiện và hiển thị

Đối với Địa chỉ email bí danh của người dùng, nó sẽ hiển thị tất cả chúng nếu có nhiều mục nhập và cũng xóa mục chính khỏi đối tượng bằng cách tìm kiếm giá trị khớp với “SMTP. ” chỉ được sử dụng cho địa chỉ chính

Các nhóm

Đối tượng Excel COM PowerShell

Báo cáo “Nhóm” sẽ hiển thị thông tin sau

  • Tên nhóm
  • Loại nhóm
  • Địa chỉ email

Báo cáo nhóm sẽ báo cáo về tất cả các nhóm. Bạn có thể phân biệt các nhóm theo loại của họ. Trong báo cáo của tôi, tôi có hầu hết các nhóm phân phối, nhưng tôi cũng có một nhóm bảo mật hỗ trợ thư

Hộp thư chung

Đối tượng Excel COM PowerShell

Báo cáo “Hộp thư dùng chung” sẽ hiển thị thông tin sau

  • Tên hộp thư dùng chung
  • Địa chỉ email chính

Liên lạc

Đối tượng Excel COM PowerShell

Báo cáo Danh bạ sẽ hiển thị thông tin sau

  • Tên Liên lạc
  • Địa chỉ email chính

thư mục công cộng

Đối tượng Excel COM PowerShell

Báo cáo “Thư mục công cộng” sẽ hiển thị cho bạn các thông tin sau

  • Tên thư mục công cộng
  • Địa chỉ email chính
  • Kích hoạt thư

Báo cáo duy nhất mất một giây để chạy là Thư mục công cộng. Điều này là do nó đang chạy 2 lệnh trong nền. Get-PublicFolder và Get-MailPublicFolder. Get-PublicFolder sẽ liệt kê TẤT CẢ các Thư mục Công cộng, có bật thư hay không. Vì vậy, để liệt kê các Thư mục công cộng hỗ trợ thư và Thư mục công cộng thông thường, tôi đang so sánh cả hai đối tượng và xóa Thư mục công cộng hỗ trợ thư khỏi đối tượng Thư mục công cộng thông thường

tên miền

Đối tượng Excel COM PowerShell

Báo cáo "Miền" sẽ hiển thị cho bạn thông tin sau

  • Tên miền
  • trạng thái mặc định
  • trạng thái xác minh

Kịch bản

Tập lệnh được liệt kê bên dưới và sẵn sàng sao chép. Không có biến hoặc bất kỳ thứ gì bạn cần thay đổi hoặc chỉnh sửa (trừ khi bạn muốn chỉnh sửa giao diện hoặc dữ liệu của báo cáo). Miễn là bạn đã đáp ứng các điều kiện tiên quyết, bạn chỉ cần sao chép cái này và chạy nó ngay lập tức

Tôi lập kế hoạch và tìm hiểu thêm về mô-đun Excel PowerShell và hy vọng sẽ có thể tạo báo cáo nhiều đối tượng thuê và thậm chí cả biểu đồ dựa trên từng tập dữ liệu. Nếu bạn đang tìm kiếm thêm thông tin tuyệt vời về giao diện COM của Excel, tôi khuyên bạn nên xem qua bài viết này

$Sku = @{
	"O365_BUSINESS_ESSENTIALS"			     = "Office 365 Business Essentials"
	"O365_BUSINESS_PREMIUM"				     = "Office 365 Business Premium"
	"DESKLESSPACK"						     = "Office 365 (Plan K1)"
	"DESKLESSWOFFPACK"					     = "Office 365 (Plan K2)"
	"LITEPACK"							     = "Office 365 (Plan P1)"
	"EXCHANGESTANDARD"					     = "Office 365 Exchange Online Only"
	"STANDARDPACK"						     = "Enterprise Plan E1"
	"STANDARDWOFFPACK"					     = "Office 365 (Plan E2)"
	"ENTERPRISEPACK"						 = "Enterprise Plan E3"
	"ENTERPRISEPACKLRG"					     = "Enterprise Plan E3"
	"ENTERPRISEWITHSCAL"					 = "Enterprise Plan E4"
	"STANDARDPACK_STUDENT"				     = "Office 365 (Plan A1) for Students"
	"STANDARDWOFFPACKPACK_STUDENT"		     = "Office 365 (Plan A2) for Students"
	"ENTERPRISEPACK_STUDENT"				 = "Office 365 (Plan A3) for Students"
	"ENTERPRISEWITHSCAL_STUDENT"			 = "Office 365 (Plan A4) for Students"
	"STANDARDPACK_FACULTY"				     = "Office 365 (Plan A1) for Faculty"
	"STANDARDWOFFPACKPACK_FACULTY"		     = "Office 365 (Plan A2) for Faculty"
	"ENTERPRISEPACK_FACULTY"				 = "Office 365 (Plan A3) for Faculty"
	"ENTERPRISEWITHSCAL_FACULTY"			 = "Office 365 (Plan A4) for Faculty"
	"ENTERPRISEPACK_B_PILOT"				 = "Office 365 (Enterprise Preview)"
	"STANDARD_B_PILOT"					     = "Office 365 (Small Business Preview)"
	"VISIOCLIENT"						     = "Visio Pro Online"
	"POWER_BI_ADDON"						 = "Office 365 Power BI Addon"
	"POWER_BI_INDIVIDUAL_USE"			     = "Power BI Individual User"
	"POWER_BI_STANDALONE"				     = "Power BI Stand Alone"
	"POWER_BI_STANDARD"					     = "Power-BI Standard"
	"PROJECTESSENTIALS"					     = "Project Lite"
	"PROJECTCLIENT"						     = "Project Professional"
	"PROJECTONLINE_PLAN_1"				     = "Project Online"
	"PROJECTONLINE_PLAN_2"				     = "Project Online and PRO"
	"ProjectPremium"						 = "Project Online Premium"
	"ECAL_SERVICES"						     = "ECAL"
	"EMS"								     = "Enterprise Mobility Suite"
	"RIGHTSMANAGEMENT_ADHOC"				 = "Windows Azure Rights Management"
	"MCOMEETADV"							 = "PSTN conferencing"
	"SHAREPOINTSTORAGE"					     = "SharePoint storage"
	"PLANNERSTANDALONE"					     = "Planner Standalone"
	"CRMIUR"								 = "CMRIUR"
	"BI_AZURE_P1"						     = "Power BI Reporting and Analytics"
	"INTUNE_A"							     = "Windows Intune Plan A"
	"PROJECTWORKMANAGEMENT"				     = "Office 365 Planner Preview"
	"ATP_ENTERPRISE"						 = "Exchange Online Advanced Threat Protection"
	"EQUIVIO_ANALYTICS"					     = "Office 365 Advanced eDiscovery"
	"AAD_BASIC"							     = "Azure Active Directory Basic"
	"RMS_S_ENTERPRISE"					     = "Azure Active Directory Rights Management"
	"AAD_PREMIUM"						     = "Azure Active Directory Premium"
	"MFA_PREMIUM"						     = "Azure Multi-Factor Authentication"
	"STANDARDPACK_GOV"					     = "Microsoft Office 365 (Plan G1) for Government"
	"STANDARDWOFFPACK_GOV"				     = "Microsoft Office 365 (Plan G2) for Government"
	"ENTERPRISEPACK_GOV"					 = "Microsoft Office 365 (Plan G3) for Government"
	"ENTERPRISEWITHSCAL_GOV"				 = "Microsoft Office 365 (Plan G4) for Government"
	"DESKLESSPACK_GOV"					     = "Microsoft Office 365 (Plan K1) for Government"
	"ESKLESSWOFFPACK_GOV"				     = "Microsoft Office 365 (Plan K2) for Government"
	"EXCHANGESTANDARD_GOV"				     = "Microsoft Office 365 Exchange Online (Plan 1) only for Government"
	"EXCHANGEENTERPRISE_GOV"				 = "Microsoft Office 365 Exchange Online (Plan 2) only for Government"
	"SHAREPOINTDESKLESS_GOV"				 = "SharePoint Online Kiosk"
	"EXCHANGE_S_DESKLESS_GOV"			     = "Exchange Kiosk"
	"RMS_S_ENTERPRISE_GOV"				     = "Windows Azure Active Directory Rights Management"
	"OFFICESUBSCRIPTION_GOV"				 = "Office ProPlus"
	"MCOSTANDARD_GOV"					     = "Lync Plan 2G"
	"SHAREPOINTWAC_GOV"					     = "Office Online for Government"
	"SHAREPOINTENTERPRISE_GOV"			     = "SharePoint Plan 2G"
	"EXCHANGE_S_ENTERPRISE_GOV"			     = "Exchange Plan 2G"
	"EXCHANGE_S_ARCHIVE_ADDON_GOV"		     = "Exchange Online Archiving"
	"EXCHANGE_S_DESKLESS"				     = "Exchange Online Kiosk"
	"SHAREPOINTDESKLESS"					 = "SharePoint Online Kiosk"
	"SHAREPOINTWAC"						     = "Office Online"
	"YAMMER_ENTERPRISE"					     = "Yammer for the Starship Enterprise"
	"EXCHANGE_L_STANDARD"				     = "Exchange Online (Plan 1)"
	"MCOLITE"							     = "Lync Online (Plan 1)"
	"SHAREPOINTLITE"						 = "SharePoint Online (Plan 1)"
	"OFFICE_PRO_PLUS_SUBSCRIPTION_SMBIZ"	 = "Office ProPlus"
	"EXCHANGE_S_STANDARD_MIDMARKET"		     = "Exchange Online (Plan 1)"
	"MCOSTANDARD_MIDMARKET"				     = "Lync Online (Plan 1)"
	"SHAREPOINTENTERPRISE_MIDMARKET"		 = "SharePoint Online (Plan 1)"
	"OFFICESUBSCRIPTION"					 = "Office ProPlus"
	"YAMMER_MIDSIZE"						 = "Yammer"
	"DYN365_ENTERPRISE_PLAN1"			     = "Dynamics 365 Customer Engagement Plan Enterprise Edition"
	"ENTERPRISEPREMIUM_NOPSTNCONF"		     = "Enterprise E5 (without Audio Conferencing)"
	"ENTERPRISEPREMIUM"					     = "Enterprise E5 (with Audio Conferencing)"
	"MCOSTANDARD"						     = "Skype for Business Online Standalone Plan 2"
	"PROJECT_MADEIRA_PREVIEW_IW_SKU"		 = "Dynamics 365 for Financials for IWs"
	"STANDARDWOFFPACK_IW_STUDENT"		     = "Office 365 Education for Students"
	"STANDARDWOFFPACK_IW_FACULTY"		     = "Office 365 Education for Faculty"
	"EOP_ENTERPRISE_FACULTY"				 = "Exchange Online Protection for Faculty"
	"EXCHANGESTANDARD_STUDENT"			     = "Exchange Online (Plan 1) for Students"
	"OFFICESUBSCRIPTION_STUDENT"			 = "Office ProPlus Student Benefit"
	"STANDARDWOFFPACK_FACULTY"			     = "Office 365 Education E1 for Faculty"
	"STANDARDWOFFPACK_STUDENT"			     = "Microsoft Office 365 (Plan A2) for Students"
	"DYN365_FINANCIALS_BUSINESS_SKU"		 = "Dynamics 365 for Financials Business Edition"
	"DYN365_FINANCIALS_TEAM_MEMBERS_SKU"	 = "Dynamics 365 for Team Members Business Edition"
	"FLOW_FREEs"							 = "Microsoft Flow Free"
	"POWER_BI_PRO"						     = "Power BI Pro"
	"O365_BUSINESS"						     = "Office 365 Business"
	"DYN365_ENTERPRISE_SALES"			     = "Dynamics Office 365 Enterprise Sales"
	"RIGHTSMANAGEMENT"					     = "Rights Management"
	"PROJECTPROFESSIONAL"				     = "Project Professional"
	"VISIOONLINE_PLAN1"					     = "Visio Online Plan 1"
	"EXCHANGEENTERPRISE"					 = "Exchange Online Plan 2"
	"DYN365_ENTERPRISE_P1_IW"			     = "Dynamics 365 P1 Trial for Information Workers"
	"DYN365_ENTERPRISE_TEAM_MEMBERS"		 = "Dynamics 365 For Team Members Enterprise Edition"
	"CRMSTANDARD"						     = "Microsoft Dynamics CRM Online Professional"
	"EXCHANGEARCHIVE_ADDON"				     = "Exchange Online Archiving For Exchange Online"
	"EXCHANGEDESKLESS"					     = "Exchange Online Kiosk"
	"SPZA_IW"							     = "App Connect"
}

$credential = Get-Credential -Message "Please enter your Office 365 credentials"
Import-Module MsOnline
Connect-MsolService -Credential $credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -AllowClobber


$excel = New-Object -ComObject Excel.Application

$excel.Visible = $true

#Create the workbook
$workbook = $excel.Workbooks.Add()
$InitalWorksheet = $workbook.Worksheets.Item(1)
$InitalWorksheet.Name = "Domains"
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Name = "Public Folders"
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Name = "Contacts"
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Name = "Shared Mailboxes"
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Name = "Groups"
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Name = "Licensed Mailboxes"



$Sheet_LicensedMailboxes = $Workbook.Worksheets.Item("Licensed Mailboxes")
$Sheet_Group = $Workbook.Worksheets.Item("Groups")
$Sheet_SharedMailboxes = $Workbook.Worksheets.Item("Shared Mailboxes")
$Sheet_Contacts = $Workbook.Worksheets.Item("Contacts")
$Sheet_PublicFolders = $Workbook.Worksheets.Item("Public Folders")
$Sheet_Domains = $Workbook.Worksheets.Item("Domains")



#Licensed Mailbox Worksheet

$Sheet_LicensedMailboxes.Activate()
$Sheet_LicensedMailboxes.ActiveSheet

$row = 1
$Column = 1
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = 'Licensed Users'


$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Size = 26
#$Sheet_LicensedMailboxes.Cells.Item($row,$column).Font.Bold=$True
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_LicensedMailboxes.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_LicensedMailboxes.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

#Create a Title for the first worksheet and adjust the font
$row = 2
$Column = 1
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = '#'
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = 'User Account'
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 3
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = 'Office 365 Licenses'
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 4
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = 'Primary E-Mail Address'
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 5
$Sheet_LicensedMailboxes.Cells.Item($row, $column) = 'Alias E-Mail Addresses'
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_LicensedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_LicensedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1


$Users = Get-Msoluser | Where-Object { $_.IsLicensed -eq $True } | Sort-Object DisplayName
$Sheet_LicensedMailboxes_Y = 3
$RowNumber = 0
$LicenseName = @()
Foreach ($User in $Users)
{
	$Row = $Sheet_LicensedMailboxes_Y++
	$DisplayName = ($User).DisplayName
	$RowNumber++
	$EmailAddresses = @()
	
	$primaryemailaddress = ($User | Select-Object -ExpandProperty proxyaddresses | Where-Object { $_ -cmatch '^SMTP' }).Trim("SMTP:")
	$EmailAddresses = @(($User | Select-Object -ExpandProperty proxyaddresses | Where-Object { $_ -cnotmatch "^SMTP:$primaryemailaddress" }) -replace "smtp:")
	
	
	#Lookup for friendly license name
	$Licenses = (($User).Licenses).AccountSkuID
	If (($Licenses).Count -gt 1)
	{
		Foreach ($License in $Licenses)
		{
			$LicenseItem = $License -split ":" | Select-Object -Last 1
			$TextLic = $Sku.Item("$LicenseItem")
			If (!($TextLic))
			{
				$fallback_Licenses = $LicenseItem
				$LicenseName += $fallback_Licenses
			}
			Else
			{
				$LicenseName += $TextLic
			}
		}
	}
	Else
	{
		$LicenseItem = $Licenses -split ":" | Select-Object -Last 1
		$TextLic = $Sku.Item("$LicenseItem")
		If (!($TextLic))
		{
			$LicenseName = $LicenseItem
		}
		Else
		{
			$LicenseName = $TextLic
		}
	}
	
	$LicenseName = ($LicenseName | Out-String).TrimEnd().Trim()
	$AllEmailAddresses = ($EmailAddresses | Out-String).Trim().TrimEnd()
	
	
	$Sheet_LicensedMailboxes.Cells.Item($Row, 1) = $RowNumber
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_LicensedMailboxes.Cells.Item($row, 1).Font.ThemeFont = 1
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		$Sheet_LicensedMailboxes.Cells.Item($Row, 2) = $DisplayName
		$Sheet_LicensedMailboxes.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_LicensedMailboxes.Cells.Item($Row, 2).VerticalAlignment = -4108
		$Sheet_LicensedMailboxes.Cells.Item($Row, 3) = $LicenseName
		$Sheet_LicensedMailboxes.Cells.Item($row, 3).Interior.ColorIndex = 15
		$Sheet_LicensedMailboxes.Cells.Item($Row, 4) = $primaryemailaddress
		$Sheet_LicensedMailboxes.Cells.Item($row, 4).Interior.ColorIndex = 15
		$Sheet_LicensedMailboxes.Cells.Item($Row, 5) = $AllEmailAddresses
		$Sheet_LicensedMailboxes.Cells.Item($row, 5).Interior.ColorIndex = 15
		
		$LicenseName = @()
	}
	Else
	{
		
		$Sheet_LicensedMailboxes.Cells.Item($Row, 2) = $DisplayName
		$Sheet_LicensedMailboxes.Cells.Item($Row, 2).VerticalAlignment = -4108
		$Sheet_LicensedMailboxes.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_LicensedMailboxes.Cells.Item($Row, 3) = $LicenseName
		$Sheet_LicensedMailboxes.Cells.Item($row, 3).Interior.ColorIndex = 2
		$Sheet_LicensedMailboxes.Cells.Item($Row, 4) = $primaryemailaddress
		$Sheet_LicensedMailboxes.Cells.Item($row, 4).Interior.ColorIndex = 2
		$Sheet_LicensedMailboxes.Cells.Item($Row, 5) = $AllEmailAddresses
		$Sheet_LicensedMailboxes.Cells.Item($row, 5).Interior.ColorIndex = 2
		$LicenseName = @()
		
	}
	
	$Sheet_LicensedMailboxes.Columns.AutoFit() | Out-Null
	$Sheet_LicensedMailboxes.Rows.AutoFit() | Out-Null
}

#Groups Worksheet

$Sheet_Group.Activate()
$Sheet_Group.ActiveSheet

#Create a Title for the first worksheet and adjust the font

$row = 1
$Column = 1
$Sheet_Group.Cells.Item($row, $column) = 'Groups'


$Sheet_Group.Cells.Item($row, $column).Font.Size = 26
#$Sheet_Group.Cells.Item($row,$column).Font.Bold=$True
$Sheet_Group.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Group.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_Group.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_Group.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_Group.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_Group.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_Group.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

$row = 2
$Column = 1
$Sheet_Group.Cells.Item($row, $column) = '#'
$Sheet_Group.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Group.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Group.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Group.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Group.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Group.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 2
$Sheet_Group.Cells.Item($row, $column) = 'Group Name'
$Sheet_Group.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Group.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Group.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Group.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Group.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Group.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 3
$Sheet_Group.Cells.Item($row, $column) = 'Group Type'
$Sheet_Group.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Group.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Group.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Group.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Group.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Group.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 4
$Sheet_Group.Cells.Item($row, $column) = 'E-Mail Address'
$Sheet_Group.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Group.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Group.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Group.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Group.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Group.Cells.Item($row, $column).Font.ThemeFont = 1


$Groups = Get-MsolGroup | Sort-Object DisplayName
$Sheet_Groups_Y = 3
$RowNumber = 0
Foreach ($Group in $Groups)
{
	$RowNumber++
	$Row = $Sheet_Groups_Y++
	$DisplayName = ($Group).DisplayName
	$GroupType = ($Group).GroupType
	$GroupEmail = ($Group).EmailAddress
	
	$GroupTypeString = $GroupType | Out-String
	$GroupTypeStringTrimEnd = $GroupTypeString.TrimEnd()
	
	$Sheet_Group.Cells.Item($Row, 1) = $RowNumber
	$Sheet_Group.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_Group.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_Group.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_Group.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_Group.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_Group.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_Group.Cells.Item($row, 1).Font.ThemeFont = 1
	
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		
		$Sheet_Group.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_Group.Cells.Item($Row, 2) = $DisplayName
		$Sheet_Group.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_Group.Cells.Item($Row, 3) = $GroupTypeStringTrimEnd
		$Sheet_Group.Cells.Item($row, 3).Interior.ColorIndex = 15
		$Sheet_Group.Cells.Item($Row, 4) = $GroupEmail
		$Sheet_Group.Cells.Item($row, 4).Interior.ColorIndex = 15
		
	}
	Else
	{
		$Sheet_Group.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_Group.Cells.Item($Row, 2) = $DisplayName
		$Sheet_Group.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_Group.Cells.Item($Row, 3) = $GroupTypeStringTrimEnd
		$Sheet_Group.Cells.Item($row, 3).Interior.ColorIndex = 2
		$Sheet_Group.Cells.Item($Row, 4) = $GroupEmail
		$Sheet_Group.Cells.Item($row, 4).Interior.ColorIndex = 2
	}
	
	
	$Sheet_Group.Columns.AutoFit() | Out-Null
	$Sheet_Group.Rows.AutoFit() | Out-Null
}


#Shared Mailboxes Sheet

$Sheet_SharedMailboxes.Activate()
$Sheet_SharedMailboxes.ActiveSheet

#Create a Title for the first worksheet and adjust the font

$row = 1
$Column = 1
$Sheet_SharedMailboxes.Cells.Item($row, $column) = 'Shared Mailboxes'


$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Size = 26
#$Sheet_SharedMailboxes.Cells.Item($row,$column).Font.Bold=$True
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_SharedMailboxes.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_SharedMailboxes.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

$row = 2
$Column = 1
$Sheet_SharedMailboxes.Cells.Item($row, $column) = '#'
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_SharedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 2
$Sheet_SharedMailboxes.Cells.Item($row, $column) = 'Shared Mailbox Name'
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_SharedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 3
$Sheet_SharedMailboxes.Cells.Item($row, $column) = 'Primary E-Mail Address'
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_SharedMailboxes.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_SharedMailboxes.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_SharedMailboxes.Cells.Item($row, $column).Font.ThemeFont = 1


$SharedMailboxes = Get-mailbox -RecipientTypeDetails sharedmailbox -Resultsize unlimited | Sort-Object Name
$Sheet_SharedMailboxes_Y = 3
$RowNumber = 0
Foreach ($SharedMailbox in $SharedMailboxes)
{
	$RowNumber++
	$Row = $Sheet_SharedMailboxes_Y++
	$DisplayName = ($SharedMailbox).Name
	$PrimarySmtpAddress = ($SharedMailbox).PrimarySmtpAddress
	
	$Sheet_SharedMailboxes.Cells.Item($Row, 1) = $RowNumber
	$Sheet_SharedMailboxes.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_SharedMailboxes.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_SharedMailboxes.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_SharedMailboxes.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_SharedMailboxes.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_SharedMailboxes.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_SharedMailboxes.Cells.Item($row, 1).Font.ThemeFont = 1
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		
		
		$Sheet_SharedMailboxes.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_SharedMailboxes.Cells.Item($Row, 2) = $DisplayName
		$Sheet_SharedMailboxes.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_SharedMailboxes.Cells.Item($Row, 3) = $PrimarySmtpAddress
		$Sheet_SharedMailboxes.Cells.Item($row, 3).Interior.ColorIndex = 15
	}
	Else
	{
		$Sheet_SharedMailboxes.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_SharedMailboxes.Cells.Item($Row, 2) = $DisplayName
		$Sheet_SharedMailboxes.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_SharedMailboxes.Cells.Item($Row, 3) = $PrimarySmtpAddress
		$Sheet_SharedMailboxes.Cells.Item($row, 3).Interior.ColorIndex = 2
	}
	
	$Sheet_SharedMailboxes.Columns.AutoFit() | Out-Null
	$Sheet_SharedMailboxes.Rows.AutoFit() | Out-Null
}


#Contact Sheet

$Sheet_Contacts.Activate()
$Sheet_Contacts.ActiveSheet

#Create a Title for the first worksheet and adjust the font

$row = 1
$Column = 1
$Sheet_Contacts.Cells.Item($row, $column) = 'Contacts'


$Sheet_Contacts.Cells.Item($row, $column).Font.Size = 26
#$Sheet_Contacts.Cells.Item($row,$column).Font.Bold=$True
$Sheet_Contacts.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Contacts.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_Contacts.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_Contacts.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_Contacts.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_Contacts.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_Contacts.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

$row = 2
$Column = 1
$Sheet_Contacts.Cells.Item($row, $column) = '#'
$Sheet_Contacts.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Contacts.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Contacts.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Contacts.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Contacts.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Contacts.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 2
$Sheet_Contacts.Cells.Item($row, $column) = 'Contact Name'
$Sheet_Contacts.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Contacts.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Contacts.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Contacts.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Contacts.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Contacts.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 3
$Sheet_Contacts.Cells.Item($row, $column) = 'Primary E-Mail Address'
$Sheet_Contacts.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Contacts.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Contacts.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Contacts.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Contacts.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Contacts.Cells.Item($row, $column).Font.ThemeFont = 1

$Contacts = Get-Contact | Sort-Object DisplayName
$Sheet_Contacts_Y = 3
$RowNumber = 0
Foreach ($Contact in $Contacts)
{
	$RowNumber++
	$Row = $Sheet_Contacts_Y++
	$DisplayName = ($Contact).DisplayName
	$ContactEmail = ($Contact).WindowsEmailAddress
	
	$Sheet_Contacts.Cells.Item($Row, 1) = $RowNumber
	$Sheet_Contacts.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_Contacts.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_Contacts.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_Contacts.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_Contacts.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_Contacts.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_Contacts.Cells.Item($row, 1).Font.ThemeFont = 1
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		
		$Sheet_Contacts.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_Contacts.Cells.Item($Row, 2) = $DisplayName
		$Sheet_Contacts.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_COntacts.Cells.Item($Row, 3) = $ContactEmail
		$Sheet_Contacts.Cells.Item($row, 3).Interior.ColorIndex = 15
	}
	Else
	{
		$Sheet_Contacts.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_Contacts.Cells.Item($Row, 2) = $DisplayName
		$Sheet_Contacts.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_COntacts.Cells.Item($Row, 3) = $ContactEmail
		$Sheet_Contacts.Cells.Item($row, 3).Interior.ColorIndex = 2
	}
	
	$Sheet_Contacts.Columns.AutoFit() | Out-Null
	$Sheet_Contacts.Rows.AutoFit() | Out-Null
}



#Public Folder Sheet

$Sheet_PublicFolders.Activate()
$Sheet_PublicFolders.ActiveSheet

#Create a Title for the first worksheet and adjust the font

$row = 1
$Column = 1
$Sheet_PublicFolders.Cells.Item($row, $column) = 'Public Folders'


$Sheet_PublicFolders.Cells.Item($row, $column).Font.Size = 26
#$Sheet_PublicFolders.Cells.Item($row,$column).Font.Bold=$True
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_Contacts.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_PublicFolders.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

$row = 2
$Column = 1
$Sheet_PublicFolders.Cells.Item($row, $column) = '#'
$Sheet_PublicFolders.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_PublicFolders.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_PublicFolders.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 2
$Sheet_PublicFolders.Cells.Item($row, $column) = 'Public Folder Name'
$Sheet_PublicFolders.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_PublicFolders.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_PublicFolders.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 3
$Sheet_PublicFolders.Cells.Item($row, $column) = 'Primary E-Mail Address'
$Sheet_PublicFolders.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_PublicFolders.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_PublicFolders.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 4
$Sheet_PublicFolders.Cells.Item($row, $column) = 'Mail Enabled'
$Sheet_PublicFolders.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_PublicFolders.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_PublicFolders.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_PublicFolders.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_PublicFolders.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_PublicFolders_Y = 3
$RowNumber = 0


$MEPFS = Get-MailPublicFolder | Sort-Object Name
$MailEnabledPFs = $MEPFS | Select-Object -ExpandProperty Name
$PF = Get-PublicFolder -recurse | Where-Object { $_.Name -notlike "IPM_SUBTREE" } | Sort-Object Name | Select-Object -ExpandProperty Name

$NonMailEnabledPFs = $PF | Where-Object { $MailEnabledPFs -notcontains $_ }
Foreach ($NonMailEnabledPF in $NonMailEnabledPFs)
{
	$Row = $Sheet_PublicFolders_Y++
	$RowNumber++
	
	$Sheet_PublicFolders.Cells.Item($Row, 1) = $RowNumber
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_PublicFolders.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_PublicFolders.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_PublicFolders.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.ThemeFont = 1
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		$Sheet_PublicFolders.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_PublicFolders.Cells.Item($Row, 2) = $NonMailEnabledPF
		$Sheet_PublicFolders.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_PublicFolders.Cells.Item($Row, 3) = "N/A"
		$Sheet_PublicFolders.Cells.Item($row, 3).Interior.ColorIndex = 15
		$Sheet_PublicFolders.Cells.Item($Row, 4) = "Not Mail-Enabled"
		$Sheet_PublicFolders.Cells.Item($row, 4).Interior.ColorIndex = 15
	}
	Else
	{
		$Sheet_PublicFolders.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_PublicFolders.Cells.Item($Row, 2) = $NonMailEnabledPF
		$Sheet_PublicFolders.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_PublicFolders.Cells.Item($Row, 3) = "N/A"
		$Sheet_PublicFolders.Cells.Item($row, 3).Interior.ColorIndex = 2
		$Sheet_PublicFolders.Cells.Item($Row, 4) = "Not Mail-Enabled"
		$Sheet_PublicFolders.Cells.Item($row, 4).Interior.ColorIndex = 2
	}
	
	$Sheet_PublicFolders.Columns.AutoFit() | Out-Null
	$Sheet_PublicFolders.Rows.AutoFit() | Out-Null
	
}
Foreach ($MEPF in $MEPFS)
{
	$Row = $Sheet_PublicFolders_Y++
	$RowNumber++
	
	$MailEnabledPFMail = $MEPF | Select-Object -ExpandProperty WindowsEmailAddress
	$MailEnabledPF = $MEPF | Select-Object -ExpandProperty Name
	
	$Sheet_PublicFolders.Cells.Item($Row, 1) = $RowNumber
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.Bold = $True
	$Sheet_PublicFolders.Cells.Item($row, 1).Interior.ColorIndex = 55
	$Sheet_PublicFolders.Cells.Item($row, 1).HorizontalAlignment = -4108
	$Sheet_PublicFolders.Cells.Item($row, 1).VerticalAlignment = -4108
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.Name = "Cambria"
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.ColorIndex = 2
	$Sheet_PublicFolders.Cells.Item($row, 1).Font.ThemeFont = 1
	
	
	$Even = $RowNumber % 2
	If ($Even -eq 0)
	{
		$Sheet_PublicFolders.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_PublicFolders.Cells.Item($Row, 2) = $MailEnabledPF
		$Sheet_PublicFolders.Cells.Item($row, 2).Interior.ColorIndex = 15
		$Sheet_PublicFolders.Cells.Item($Row, 3) = $MailEnabledPFMail
		$Sheet_PublicFolders.Cells.Item($row, 3).Interior.ColorIndex = 15
		$Sheet_PublicFolders.Cells.Item($Row, 4) = "Mail-Enabled"
		$Sheet_PublicFolders.Cells.Item($row, 4).Interior.ColorIndex = 15
	}
	Else
	{
		$Sheet_PublicFolders.Cells.Item($Row, 1).Font.Bold = $True
		$Sheet_PublicFolders.Cells.Item($Row, 2) = $MailEnabledPF
		$Sheet_PublicFolders.Cells.Item($row, 2).Interior.ColorIndex = 2
		$Sheet_PublicFolders.Cells.Item($Row, 3) = $MailEnabledPFMail
		$Sheet_PublicFolders.Cells.Item($row, 3).Interior.ColorIndex = 2
		$Sheet_PublicFolders.Cells.Item($Row, 4) = "Mail-Enabled"
		$Sheet_PublicFolders.Cells.Item($row, 4).Interior.ColorIndex = 2
	}
	
	$Sheet_PublicFolders.Columns.AutoFit() | Out-Null
	$Sheet_PublicFolders.Rows.AutoFit() | Out-Null
	
}



#Domain Sheet
$Sheet_Domains.Activate()
$Sheet_Domains.ActiveSheet

#Create a Title for the first worksheet and adjust the font

$row = 1
$Column = 1
$Sheet_Domains.Cells.Item($row, $column) = 'Domains'


$Sheet_Domains.Cells.Item($row, $column).Font.Size = 26
#$Sheet_Group.Cells.Item($row,$column).Font.Bold=$True
$Sheet_Domains.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeFont = 1
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeColor = 4
$Sheet_Domains.Cells.Item($row, $column).Font.ColorIndex = 55
$Sheet_Domains.Cells.Item($row, $column).Font.Color = 8210719

$range = $Sheet_Domains.Range("a1", "c1")
$range.Style = 'Title'
$range.Font.Size = 26

$range = $Sheet_Domains.Range("a1", "c1")
$range.Merge() | Out-Null
$range.VerticalAlignment = -4160

$row = 2
$Column = 1
$Sheet_Domains.Cells.Item($row, $column) = '#'
$Sheet_Domains.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Domains.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Domains.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Domains.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Domains.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeFont = 1


$row = 2
$Column = 2
$Sheet_Domains.Cells.Item($row, $column) = 'Domain Name'
$Sheet_Domains.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Domains.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Domains.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Domains.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Domains.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 3
$Sheet_Domains.Cells.Item($row, $column) = 'Default'
$Sheet_Domains.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Domains.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Domains.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Domains.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Domains.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeFont = 1

$row = 2
$Column = 4
$Sheet_Domains.Cells.Item($row, $column) = 'Verified'
$Sheet_Domains.Cells.Item($row, $Column).Font.Bold = $True
$Sheet_Domains.Cells.Item($row, $Column).Interior.ColorIndex = 55
$Sheet_Domains.Cells.Item($row, $Column).HorizontalAlignment = -4108
$Sheet_Domains.Cells.Item($row, $column).Font.Name = "Cambria"
$Sheet_Domains.Cells.Item($row, $column).Font.ColorIndex = 2
$Sheet_Domains.Cells.Item($row, $column).Font.ThemeFont = 1


$Domains = Get-MsolDomain | Sort-Object Name
$Sheet_Domains_Y = 3
$RowNumber = 0
Foreach ($Domain in $Domains)
{
	$Row = $Sheet_Domains_Y++
	$RowNumber++
	$DisplayName = ($Domain).Name
	$DefaultStatus = ($Domain).IsDefault
	$Verified = (($Domain).Status | Out-String).TrimEnd()
	
	If ($DefaultStatus -eq $True)
	{
		$Sheet_Domains.Cells.Item($Row, 1) = $RowNumber
		$Sheet_Domains.Cells.Item($row, 1).Font.Bold = $True
		$Sheet_Domains.Cells.Item($row, 1).Interior.ColorIndex = 55
		$Sheet_Domains.Cells.Item($row, 1).HorizontalAlignment = -4108
		$Sheet_Domains.Cells.Item($row, 1).VerticalAlignment = -4108
		$Sheet_Domains.Cells.Item($row, 1).Font.Name = "Cambria"
		$Sheet_Domains.Cells.Item($row, 1).Font.ColorIndex = 2
		$Sheet_Domains.Cells.Item($row, 1).Font.ThemeFont = 1
		
		$Sheet_Domains.Cells.Item($Row, 2) = $DisplayName
		$Sheet_Domains.Cells.Item($Row, 3) = $DefaultStatus
		$Sheet_Domains.Cells.Item($Row, 4) = $Verified
		
		$Sheet_Domains.Cells.Item($Row, 2).Font.Bold = $True
		$Sheet_Domains.Cells.Item($Row, 3).Font.Bold = $True
		$Sheet_Domains.Cells.Item($row, 2).Interior.ColorIndex = 6
		$Sheet_Domains.Cells.Item($row, 3).Interior.ColorIndex = 6
		$Sheet_Domains.Cells.Item($row, 4).Interior.ColorIndex = 6
	}
	Else
	{
		
		$Sheet_Domains.Cells.Item($Row, 1) = $RowNumber
		$Sheet_Domains.Cells.Item($row, 1).Font.Bold = $True
		$Sheet_Domains.Cells.Item($row, 1).Interior.ColorIndex = 55
		$Sheet_Domains.Cells.Item($row, 1).HorizontalAlignment = -4108
		$Sheet_Domains.Cells.Item($row, 1).VerticalAlignment = -4108
		$Sheet_Domains.Cells.Item($row, 1).Font.Name = "Cambria"
		$Sheet_Domains.Cells.Item($row, 1).Font.ColorIndex = 2
		$Sheet_Domains.Cells.Item($row, 1).Font.ThemeFont = 1
		
		
		$Even = $RowNumber % 2
		If ($Even -eq 0)
		{
			$Sheet_Domains.Cells.Item($Row, 2) = $DisplayName
			$Sheet_Domains.Cells.Item($row, 2).Interior.ColorIndex = 15
			$Sheet_Domains.Cells.Item($Row, 3) = $DefaultStatus
			$Sheet_Domains.Cells.Item($row, 3).Interior.ColorIndex = 15
			$Sheet_Domains.Cells.Item($Row, 4) = $Verified
			$Sheet_Domains.Cells.Item($row, 4).Interior.ColorIndex = 15
		}
		Else
		{
			$Sheet_Domains.Cells.Item($Row, 2) = $DisplayName
			$Sheet_Domains.Cells.Item($row, 2).Interior.ColorIndex = 2
			$Sheet_Domains.Cells.Item($Row, 3) = $DefaultStatus
			$Sheet_Domains.Cells.Item($row, 3).Interior.ColorIndex = 2
			$Sheet_Domains.Cells.Item($Row, 4) = $Verified
			$Sheet_Domains.Cells.Item($row, 4).Interior.ColorIndex = 2
		}
		
		$Sheet_Domains.Cells.Item($Row, 2).Font.Bold = $False
		$Sheet_Domains.Cells.Item($Row, 3).Font.Bold = $False
	}
	
	$Sheet_Domains.Columns.AutoFit() | Out-Null
	$Sheet_Domains.Rows.AutoFit() | Out-Null
}



 

 

 

Đối tượng Excel COM PowerShell

Brad Wyatt

Tên tôi là Bradley Wyatt;

Đối tượng COM trong PowerShell là gì?

ComObject hoặc COM đơn giản, tăng phạm vi hoạt động PowerShell. Một cách để xem các đối tượng COM là một cơ chế để PowerShell khởi chạy các chương trình , chẳng hạn như bắt chước lệnh RUN. Một cách nhìn khác về ComObjects là thực hiện vai trò do VBScript đảm nhận trước đó.

PowerShell có thể tương tác với Excel không?

ImportExcel là mô-đun PowerShell cho phép bạn nhập hoặc xuất dữ liệu trực tiếp từ bảng tính Excel mà không cần cài đặt Microsoft Excel trên máy tính . Trong hướng dẫn này, bạn sẽ học cách làm việc với Import-Excel và Export-Excel.

Làm cách nào để lấy dữ liệu từ Excel bằng PowerShell?

Bạn có thể đọc bảng tính Excel bằng các đối tượng COM từ powershell. .
$Tệp = "C. \gpo. xlsx"
$Excel = Đối tượng mới -ComObject Excel. Đăng kí
$WorkBook = $Excel. sách bài tập. .
$WorkSheet = $WorkBook. bảng tính. .
$UsedRange = $WorkSheet. Phạm vi đã sử dụng
$Rows = $UsedRange. hàng. .
$Objs = @()
for($Row=2; $Row -le $Rows; $Row++){

Làm cách nào để chuyển đổi Excel sang CSV bằng PowerShell?

chuyển xlsx sang csv bằng powershell .
foreach ($ws bằng $wb. Bảng tính) {
$ws. SaveAs("$myDir\" + $File + ". csv", 6)
$Excel. Từ bỏ()