# Reporting and Logging

{% hint style="info" %}
If you are looking for the returned reports from each function check [UcmPsTools Cmdlet Reporting](https://docs.ucmadscientist.com/ucmpstools-in-depth/ucmpstools-cmdlet-status-reporting)
{% endhint %}

## UCM Report Cmdlets

A collection of cmdlets for creating, managing and exporting reports

[Initialize-UcmReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/initialize-ucmreport)\
[New-UcmReportItem](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/new-ucmreportitem)\
[New-UcmReportStep](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/new-ucmreportstep)\
[Complete-UcmReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/complete-ucmreport)\
[Export-UcmHtmlReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/export-ucmhtmlreport)\
[Export-UcmCsvReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/export-ucmcsvreport)

## Other Reporting Cmdlets

[Search-UcmCsOnPremNumberRange](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/search-ucmcsonpremnumberrange) - Find what resource is using a number on-prem\
[Write-UcmLog](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/write-ucmlog) - A function used by almost every function in UcmPsTools. Great logging utility

### About UCM Reporting Cmdlets

These cmdlets allow you to track the progress of actions in your scripts which you can then export to a variety of formats including HTML and CSV (more info)

Turn your post-script reports from this

![](https://2626687514-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYXWvgmjV6LfJJPWnnFcX%2Fuploads%2Fchdq1udlZ4v2MLPHZY1z%2Fimage.png?alt=media\&token=ff113d2d-df2c-44a6-a014-7f4995f6bfa1)

into HTML like this

![](https://2626687514-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYXWvgmjV6LfJJPWnnFcX%2Fuploads%2FwrIFhuiK39dv36FVh52N%2Fimage.png?alt=media\&token=f10d251e-23e5-4cdb-88f5-7ce9a7c01102)

Or CSV's like this

![](https://2626687514-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYXWvgmjV6LfJJPWnnFcX%2Fuploads%2FW3s49ncpfOpqNqoPEnlD%2Fimage.png?alt=media\&token=a57c8d15-5679-4866-ae3d-c7eea2111eff)

Simply start by calling [Initialize-UcmReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/initialize-ucmreport)!

### Using the UCM Report Cmdlets

Start off by calling [Initialize-UcmReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/initialize-ucmreport), this creates a global variable to store the status of the report.&#x20;

Then when you're ready, add a line to the report. Call [New-UcmReportItem](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/new-ucmreportitem). This creates a new PSObject to track the status against.&#x20;

Each **ReportItem** is its own item for tracking and can have multiple **ReportSteps**, aka actions associated with it. For example, above, we create a new **ReportItem** for every user we are processing.

<details>

<summary>New-UcmReportItem Parameters</summary>

New-UcmReportItem expects two parameters \
\
\&#xNAN;**-LineTitle:**  This is the title of the first row in the report and should be the same for every ReportItem. In the above example, we used "Username"\
\
\&#xNAN;**-LineMessage:** This is the value we are setting the first cell to and should be unique to prevent conflicts. In the above example "AppleJack" was used the first time we called New-UcmReportItem, and "Discord" the second time

</details>

Once you have created a **ReportItem**, we can start logging steps against it using [New-UcmReportStep](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/new-ucmreportstep)

**ReportSteps** are typically items performed against a **ReportItem** so again using the report above, each step such as assigning a licence, applying a policy etc to a user (the ReportItem) and can be thought of as a column in the row.

<details>

<summary>New-UcmReportStep Parameters</summary>

New-UcmReportSteps expects two parameters \
\
\&#xNAN;**-StepName:** This is the name of the Step, translating to the title of the column for each of the rows of the first row, for example, "Enable User"\
\
\&#xNAN;**-StepResult:** This is the value of the action performed. This is a freeform field, but should it contain "OK" "Warn" or "Error", HTML reports will automatically have their cells coloured Green, Yellow and Red respectively.&#x20;

</details>

{% hint style="info" %}
If you add any of the following keywords to the ReportStep items, their cells will be colour coded based on the keyword\
\
"OK": Green\
"Warn"/"Warning": Yellow\
"Error": Red
{% endhint %}

Once you have finished working with that item, user, or whatever and are ready to move on to the next line, Call [New-UcmReportItem](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/new-ucmreportitem) with the next item, or if you're ready to wrap things up, call [Complete-UcmReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/complete-ucmreport) to add the last step into the report object. Ready to be exported using either [Export-UcmCsvReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/export-ucmcsvreport) or [Export-UcmHtmlReport](https://docs.ucmadscientist.com/using-ucmpstools/cmdlet-reference/reporting-and-logging/export-ucmhtmlreport) (you can call both!)
