I’ve seen many scripts create an Excel file and cease in the mean time the rows seem. That’s sufficient for an information export, however it’s not but a workbook I might give to an operations group. Individuals must know the place to start out, tips on how to attain the element, who owns the following motion, and which values deserve consideration.
This instance builds that type of workbook from PowerShell objects. It makes use of companies, house owners, well being scores, incidents, tendencies, and remediation actions, matching the Phrase report on this sequence. The compact model creates six sheets with formulation, tables, validation, conditional formatting, charts, navigation, and a read-back verify. The complete showcase provides extra knowledge and print settings.
Earlier than you begin
Use PowerShell 7 and set up the present public modules used for this text:
Set up-Module PSWriteOffice -Scope CurrentUser -Power
Import-Module PSWriteOffice
Run the examples from a folder the place you possibly can write the generated recordsdata. Change the pattern service knowledge after the primary profitable run.
Workbook form
The full showcase script features a bigger dataset and extra formatting. The blocks under construct the smaller two-service workbook proven right here.
It produces a workbook with these sheets:
Index: generated desk of contents with hyperlinks and backlinksAbstract: KPI formulation and a standing legend chartProviders: the principle operational deskDevelopment: month-by-month availability, incident, and automation knowledgeProprietor Abstract: grouped possession view for follow-upNotes: hidden technology notes for audit/debugging
I cut up the sheets by the questions individuals ask. Administration begins with the abstract, an engineer filters the service rows, and an proprietor can soar on to the motion queue or development knowledge.
Writing from objects
The workbook begins with regular PowerShell objects. In an actual job, they might come from REST APIs, Microsoft Graph, monitoring probes, CSV recordsdata, Lively Listing, or a earlier PSWriteOffice learn.
$companies = @(
[pscustomobject]@{
Service="Identification Sync"
Proprietor="Platform"
Well being = 98
Incidents = 1
Standing="Wholesome"
Proof="identity-sync"
}
[pscustomobject]@{
Service="Distant Entry"
Proprietor="Safety"
Well being = 76
Incidents = 7
Standing="Danger"
Proof="remote-access"
}
)
$development = @(
[pscustomobject]@{ Month="Jan"; Availability = 99.1; Incidents = 14; Automation = 62 }
[pscustomobject]@{ Month="Feb"; Availability = 99.2; Incidents = 12; Automation = 66 }
[pscustomobject]@{ Month="Mar"; Availability = 99.4; Incidents = 10; Automation = 71 }
[pscustomobject]@{ Month="Apr"; Availability = 99.3; Incidents = 11; Automation = 74 }
[pscustomobject]@{ Month="Could"; Availability = 99.6; Incidents = 8; Automation = 79 }
[pscustomobject]@{ Month="Jun"; Availability = 99.7; Incidents = 6; Automation = 83 }
)
$legend = @(
[pscustomobject]@{ Standing="Wholesome"; That means = 'Secure service posture' }
[pscustomobject]@{ Standing="Watch"; That means = 'Proprietor follow-up required' }
[pscustomobject]@{ Standing="Danger"; That means = 'Rapid motion required' }
)
$statusMix = $companies |
Group-Object Standing |
ForEach-Object { [pscustomobject]@{ Standing = $_.Identify; Depend = $_.Depend } }
$ownerSummary = $companies |
Group-Object Proprietor |
ForEach-Object {
[pscustomobject]@ Measure-Object Incidents -Sum).Sum
}
$path=".Operational-Dashboard.xlsx"
The script writes actual Excel construction fairly than adorning a flat export. Tables stay tables, formulation recalculate, hyperlinks work, and the operations group can preserve enhancing the workbook after technology.
If a local desk is all you want, begin with the quick pipeline:
$companies | Export-OfficeExcel `
-Path '.ServiceHealth.xlsx' `
-WorksheetName 'Providers' `
-TableName 'ServiceHealth' `
-AutoFit `
-FreezeTopRow
I transfer to the bigger DSL solely as a result of this workbook wants a number of sheets, formulation, charts, validation, and navigation. For a single desk, the quick export above is the higher script.
The place this suits subsequent to ImportExcel
Many PowerShell customers have already got good reporting scripts constructed with ImportExcel. If a type of scripts creates the workbook you want, preserve it. I take advantage of PSWriteOffice when Excel is a part of a wider doc workflow, after I want to examine or restore workbook construction, or when the identical objects additionally feed Phrase, PowerPoint, PDF, CSV, or electronic mail output.
The PSWriteOffice repository has a public comparability and reproducible benchmark matrix. It runs equal workbook duties aspect by aspect and validates the recordsdata. Deal with these outcomes as a place to begin on your workload, fairly than a cause to rewrite a report that already works.
Constructing the abstract sheet
The abstract sheet combines labeled formulation, styled tables, and a standing chart.
$workbook = New-OfficeExcel -Path $path -NoSave
ExcelSheet -Doc $workbook 'Abstract'
Set-OfficeExcelChartDataLabels -ShowValue $true -ShowCategoryName $true -PassThru
The result’s a traditional .xlsx. It may be filtered, recalculated, charted, and edited in desktop Excel.
Element sheet: the place the work occurs
The Providers sheet is the place the follow-up occurs. It makes use of a structured desk, a validation checklist, a coloration scale, knowledge bars, traffic-light icons, and proof hyperlinks generated from a header.
ExcelSheet -Doc $workbook 'Providers' {
ExcelTable -Information ($companies | Choose-Object Service, Well being, Incidents, Proprietor, Standing, Proof) `
-TableName 'ServiceHealth' `
-StartRow 1 `
-StartColumn 1 `
-TableStyle 'TableStyleMedium9' `
-AutoFit
ExcelFreeze -TopRows 1
ExcelValidationList -Vary 'E2:E50' -Values 'Wholesome','Watch','Danger'
ExcelConditionalColorScale -Vary 'B2:B3' -StartColor '#F8696B' -EndColor '#63BE7B'
ExcelConditionalDataBar -Vary 'C2:C3' -Coloration '#5B9BD5'
ExcelConditionalIconSet -Vary 'B2:B3' -IconSet ThreeTrafficLights1
ExcelChart -Vary 'A1:B3' `
-Row 12 `
-Column 1 `
-Sort BarClustered `
-Title 'Service well being rating'
ExcelUrlLinksByHeader `
-Header 'Proof' `
-TableName 'ServiceHealth' `
-UrlScript { param($textual content) "https://evotec.xyz/docs/$textual content" } `
-TitleScript { param($textual content) "Open $textual content" }
}
That is what I need from PowerShell-generated Excel: repeatable enter knowledge and a workbook that also feels regular when an individual opens it.
Development and possession
I add separate development and owner-summary sheets so the workbook can reply two totally different questions: “what modified?” and “who must act?”
ExcelSheet -Doc $workbook 'Development' {
ExcelTable -Information $development -TableName 'TrendData' -TableStyle 'TableStyleMedium2' -AutoFit
foreach ($column in 1..4) { ExcelColumn -Column $column -Width 16 }
ExcelChart -Vary 'A1:B7' `
-Row 10 `
-Column 1 `
-Sort Line `
-Title 'Month-to-month availability (%)' `
-PassThru |
Set-OfficeExcelChartLegend -Place Backside -PassThru |
Set-OfficeExcelChartDataLabels -ShowValue $true -Place Prime -PassThru |
Set-OfficeExcelChartStyle -StyleId 251 -ColorStyleId 10
}
ExcelSheet -Doc $workbook 'Proprietor Abstract' {
ExcelTable -Information $ownerSummary -TableName 'OwnerSummary' -TableStyle 'TableStyleMedium5' -AutoFit
ExcelConditionalDataBar -Vary 'D2:D20' -Coloration '#ED7D31'
ExcelConditionalIconSet -Vary 'C2:C20' -IconSet ThreeTrafficLights1
}
The development chart reveals availability alone. Mixing percentages and incident counts on one axis made the chart tougher to learn. The proprietor abstract stays a desk as a result of reviewers want an motion queue. When the evaluation wants interactive regrouping, the companion Recipe-Excel-PivotAndSparklines.ps1 reveals PivotTables and row-level tendencies in a smaller script.
Hidden notes and navigation
The hidden Notes sheet retains technology particulars with the workbook with out placing them in entrance of each reader. As soon as all content material sheets exist, I generate navigation, save, and shut the reside workbook.
ExcelSheet -Doc $workbook 'Notes' {
ExcelCell -Handle 'A1' -Worth 'Era Notes'
ExcelCell -Handle 'A2' -Worth 'This sheet is hidden and carries audit/debugging inputs.'
ExcelCell -Handle 'A5' -Worth 'Supply'
ExcelCell -Handle 'B5' -Worth 'Examples/Showcase/Showcase-Excel-OperationalDashboard.ps1'
ExcelSheetVisibility -Conceal
}
ExcelTableOfContents `
-Doc $workbook `
-SheetName 'Index' `
-IncludeNamedRanges `
-AddBackLinks `
-BackLinkText 'Again to Index'
$workbook | Shut-OfficeExcel -Save
Studying and proving the workbook form
After saving, I reopen the workbook and verify the construction readers depend on.
$workbook = Get-OfficeExcel -Path $path -ReadOnly
$sheets = @($workbook.Sheets)
$abstract = [pscustomobject]@{
SheetCount = $sheets.Depend
TableCount = @(Get-OfficeExcelTable -Doc $workbook).Depend
ChartCount = ($sheets | ForEach-Object { $_.Charts.Depend } | Measure-Object -Sum).Sum
}
$sheetSummary = $sheets |
Choose-Object Identify, UsedRangeA1, @{ Identify="ChartCount"; Expression = { $_.Charts.Depend } }
$workbook | Shut-OfficeExcel
$abstract
$sheetSummary
For the generated dashboard, the form verify reviews:
The generated workbook additionally contains navigation hyperlinks, proof hyperlinks, and a hidden notes sheet for audit context.
These counts are helpful in CI and provides me a fast description of the workbook with out opening Excel.
For data-level checks, the identical workbook could be learn again with vary and desk readers:
$serviceRows = Get-OfficeExcelRange `
-Path $path `
-Sheet 'Providers' `
-Vary 'A1:H9'
$usedRange = Get-OfficeExcelUsedRange `
-Path $path `
-Sheet 'Providers' `
-AsDataTable
$namedRanges = Get-OfficeExcelNamedRange -Path $path
Now the script checks each the workbook form and the values that matter.
From Home windows occasions to a delivered report
The enter objects can come from wherever. On this instance, a scheduled Home windows operations job queries PSEventViewer, writes the element to Excel, creates a compact PDF abstract, and lets Mailozaurr ship each recordsdata:
Import-Module PSEventViewer
Import-Module PSWriteOffice
Import-Module Mailozaurr
$outputDirectory = (New-Merchandise -ItemType Listing -Path (Be a part of-Path $PSScriptRoot 'Output') -Power).FullName
$excelPath = Be a part of-Path $outputDirectory 'System-Occasions.xlsx'
$pdfPath = Be a part of-Path $outputDirectory 'System-Occasions.pdf'
$occasions = @(
Get-EVXEvent `
-LogName System `
-TimePeriod Last24Hours `
-ReadMode Message `
-MaxEvents 500 |
Choose-Object TimeCreated, MachineName, ProviderName, Id, LevelDisplayName, Message
)
$occasions | Export-OfficeExcel `
-Path $excelPath `
-WorksheetName Occasions `
-TableName SystemEvents `
-AutoFit `
-FreezeTopRow
New-OfficePdf -Path $pdfPath Choose-Object -First 25 TimeCreated, MachineName, ProviderName, Id, LevelDisplayName)
$mailCredential = Get-Secret -Identify 'Operations-Smtp-Credential'
Ship-EmailMessage `
-From 'reviews@instance.com' `
-To 'operations@instance.com' `
-Topic 'Day by day Home windows occasion report' `
-Textual content 'The detailed Excel workbook and assessment PDF are hooked up.' `
-Attachment $excelPath, $pdfPath `
-Server 'smtp.instance.com' `
-Credential $mailCredential `
-UseSsl
Every module has one job. PSEventViewer queries and initiatives the occasions, PSWriteOffice creates the workbook and PDF, and Mailozaurr handles authentication and supply. They meet by way of odd PowerShell objects and file paths.
Get-Secret comes from Microsoft.PowerShell.SecretManagement. In a scheduled activity or CI job, use the key supplier that atmosphere already trusts as an alternative of placing credentials within the report script.
Efficiency and scale
I construct the dashboard round tables and ranges so the script doesn’t format hundreds of cells one after the other by way of the pipeline.
- Use
ExcelTable -Information $objectsfor rectangular datasets. - Use formulation for values Excel ought to preserve recalculating after the file is opened.
- Use table-based charts so the chart follows the info form.
- Apply conditional formatting to ranges as an alternative of formatting each cell in a loop.
- Hold read-back validation centered on abstract counts, used ranges, desk names, and demanding values.
- Use hidden sheets for technology notes and audit metadata as an alternative of writing separate sidecar recordsdata.
The repository benchmark suite covers objects, DataTable, IDataReader, report workbooks, append, replace, charts, pivots, and read-back towards options that assist the identical activity. I don’t scale back that to at least one headline quantity as a result of desk dimension, varieties, AutoFit, charts, formulation, updates, and read-back all change the outcome. Run the situation closest to your workload on the goal machine and preserve validation enabled.
For a bigger stock, cut up the seen sheets by workflow: abstract, particulars, possession, development, and notes. Readers get smaller tables and clearer locations to work.
The place I take advantage of the identical format
With totally different enter objects, the identical workbook form can deal with:
- stock dashboards with asset element, proprietor queue, and stale-data warnings
- safety posture workbooks with danger scoring, proof hyperlinks, and motion monitoring
- migration trackers with validation lists, conditional formatting, and grouped house owners
- service availability scorecards with development charts and month-to-month snapshots
- workbook QA reviews the place read-back checks confirm tables, charts, hyperlinks, and hidden sheets
Test the ultimate workbook the place individuals will use it
The compact instance makes use of odd tables for its proprietor queue. PivotTables and sparklines are separate choices when readers want interactive regrouping or compact row-level tendencies; see the pivot and sparkline recipe.
Structural read-back confirms what’s saved within the workbook. I additionally open consultant reviews within the spreadsheet software readers use, as a result of recalculation, chart labels, and print format are visible conduct. Availability and automation are percentages whereas incidents are counts, so preserve them on separate charts or configure a secondary axis explicitly.


