# Active Directory DHCP Report to HTML or EMAIL with zero HTML knowledge

I’m pretty addicted to reading blog posts. I saw this new blog post the other day, where the author created the DHCP HTML report, and he did it by manually building headers, footers, table borders, and finally, adding some coloring to the percentage of DHCP being in use. It’s the “standard” approach to build HTML in PowerShell, and I’ve seen a similar path before, but that got me thinking how much time it would take for me to replicate the very same functionality using PSWriteHTML module.

blog

12 Jul 2020 en

![Active Directory DHCP Report to HTML or EMAIL with zero HTML knowledge](/wp-content/uploads/2020/07/img_5f0b1221cd229.png)

[View images (14)](#pf-content-image-1-0)

I'm pretty addicted to reading blog posts. I saw this new blog post the other day, where the author created the **DHCP HTML** report, and he did it by manually building headers, footers, table borders, and finally, adding some coloring to the percentage of **DHCP **being in use. It's the “standard” approach to build **HTML **in **PowerShell**, and I've seen a similar path before, but that got me thinking how much time it would take for me to replicate the very same functionality using **PSWriteHTML** module.If you're interested in the other article, you can find it [**here**](https://spiderzebra.com/2020/07/09/generate-a-dhcp-report-via-powershell/). The essentials parts, however, that I wanted to focus on are visuals and part of the code to generate it. The next two images are from the other article and are here to illustrate what we are trying to accomplish (**1st image**) and what we are trying to avoid (**2nd image**).

[!\[Example DHCP utilization report table with highlighted scope usage percentages.\](/wp-content/uploads/2020/07/img_5f088c4e39c72.png)](/wp-content/uploads/2020/07/img_5f088c4e39c72.png)

The important part to generate it

[!\[PowerShell and HTML code snippet used to build the original DHCP report table.\](/wp-content/uploads/2020/07/img_5f088c85c81d3.png)](/wp-content/uploads/2020/07/img_5f088c85c81d3.png)

As you see above, the visual part is a clear and readable table; however, the code to do so, except for PowerShell knowledge, also requires **HTML **building skills. You have to know what each tag does and how it impacts visuals. You could, of course, argue that it's just copy/paste and you're done, so in the long run, it doesn't matter, but I'm here to show you another way to do things.

### 💡 DHCP Reporting – Data gathering

Let's see how we can do it my way. My approach uses the same code to gather the **DHCP servers** from **Active Directory** and then going thru each scope, finally putting it in a single array called **Output**.

```powershell
# Dynamically pulling the DHCP servers in a Active Directory domain
$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}
```

When you run the above code, you should get everything in one table. The approach here is – we separate data preparation from reporting. This allows us to build our dataset and use it for anything – be it HTML report, export to Excel, or send via email.

```powershell
$Output | Format-Table
```

[!\[PowerShell table output listing DHCP servers, scopes, lease ranges, and utilization values.\](/wp-content/uploads/2020/07/img_5f088ea24d7f4.png)](/wp-content/uploads/2020/07/img_5f088ea24d7f4.png)

Now that I've my data in a variable I can install my **[PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML)** PowerShell module.

```powershell
Install-Module PSWriteHTML -Force
```

That's it. The module is installed and with it, you're ready to build your HTML reports with almost zero effort on your side.

### 💡 DHCP Reporting – Export to HTML

Ok, so we have our data saved in **$Output** variable, we have **PowerShell** module to create **HTML** installed now we can build our HTML.

```powershell
$Output | Out-HtmlView
```

And that's it. When you call **Out-HTMLView**, it automatically generates **HTML **code for you and opens it up in the default browser.

[!\[Basic Out-HtmlView page showing the DHCP report without JavaScript enhancements.\](/wp-content/uploads/2020/07/img_5f088fd58d5d0.png)](/wp-content/uploads/2020/07/img_5f088fd58d5d0.png)

As you see above, the table contains all information that we require, but it also was executed on a server where I have **JavaScript disabled**. In such a case, **PSWriteHTML **will give users the ability to see a minimal **HTML **version. If you have JavaScript enabled or/and using the modern browser the output would be much better, giving you sort, search, export to Excel, CSV, or even PDF.

[!\[Interactive DHCP report in Out-HtmlView with search, export, and table controls.\](/wp-content/uploads/2020/07/img_5f08911e929bf.png)](/wp-content/uploads/2020/07/img_5f08911e929bf.png)

And in case the screen is smaller, columns that wouldn't fit on the screen will simply hide away and will be accessible under the plus button.

[!\[Responsive DHCP report with hidden columns accessible from expandable row details.\](/wp-content/uploads/2020/07/img_5f0890f27d17a.png)](/wp-content/uploads/2020/07/img_5f0890f27d17a.png)

Cool right? Out-HtmlView has a lot of parameters that one can use on a daily basis, for other types of data. This is just one of many examples and I encourage you to try and explore it a bit. Its use case is mostly limited to opening HTML right there, during our processing. Of course, you can save the file, filter things in it, disable or remove buttons as required.

```powershell
$Output | Out-HtmlView -FilePath $Env:USERPROFILE\Desktop\MyReport.html -Title 'DHCP Servers' -HideFooter -PreventShowHTML
```

However, nothing is stopping you from using it for reporting if you wish to. As you can see above, I've told **Out-HtmlView** where to save the file, how to name it, to hide footer, and finally, to not automatically open it in a browser.

### 💡 DHCP Reporting – Advanced Out-HTMLView

Of course, you may say now that I've merely displayed the data in **HTML, **but I've no way delivered the same visual effect that the author in the other article. So let's do that, shall we? **Out-HTMLView** isn't designed for advanced reporting, but it does support the same sets of options as **New-HTMLTable**, which is part of **PSWriteHTML**. Some months ago, I added a couple of features that allow you to quickly build conditional formatting or advanced headers without diving into **HTML**.

```powershell
$Output | Out-HtmlView {
    New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
    New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType number
} -HideFooter -Title 'DHCP Servers'
```

Six lines of code, dynamically built, easily can be adjusted for any reporting, not only for **DHCP** scopes.

[!\[DHCP report with conditional formatting highlighting percentage-in-use values by color.\](/wp-content/uploads/2020/07/img_5f08c083c98df.png)](/wp-content/uploads/2020/07/img_5f08c083c98df.png)

Of course, since I don't have a busy DHCP server at the moment, you only see green color, but trust me on that – it would be multicolor. You could add as many conditions as you want, for different column names, and even overwrite some values on demand if needed. But still, we've just talked about conditions, and our author managed to do more.

```powershell
$Output | Out-HtmlView {
    New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
    New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
    New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
    New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
    New-TableHeader -Names 'Subnet Mask','Start Range','End Range','Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray
} -HideFooter -Title 'DHCP Servers'
```

No javascript enabled view

[!\[No-JavaScript DHCP report with grouped headers and formatted utilization columns.\](/wp-content/uploads/2020/07/img_5f08c97244961.png)](/wp-content/uploads/2020/07/img_5f08c97244961.png)

Or if you have JavaScript enabled, more advanced view

[!\[Enhanced DHCP report in a browser with grouped headers, filtering, and formatted columns.\](/wp-content/uploads/2020/07/img_5f08c9ed1d856.png)](/wp-content/uploads/2020/07/img_5f08c9ed1d856.png)

It's up to you to choose proper colors, alignment, background color, the color of text, or whether it's bold or not. You can add titles, modify headers, all by using basic **PowerShell knowledge**, and **zero HTML**.

### 💡 DHCP Reporting – Advanced Out-HTMLView Full Code

So with just 40 lines of code, I can gather **DHCP** data scopes and output them in **HTML** form, and I can do so without knowing how to build **HTML**, what each tag means, and how everything in **HTML** is connected with **CSS** and **JavaScript**.

```powershell
# Dynamically pulling the DHCP servers in a Active Directory domain
$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}

$Output | Out-HtmlView {
    New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
    New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
    New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
    New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
    New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
    New-TableHeader -Names 'Subnet Mask','Start Range','End Range','Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray
} -HideFooter -Title 'DHCP Servers' -FilePath $env:USERPROFILE\Desktop\MyDHCPReport.html
```

### 💡 DHCP Reporting – Sending reports to email

But **Out-HTMLView** is just one command of many available within **[PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML)**. Ever since **Emailimo** was integrated you can send pretty emails using readable code.

```powershell
Email -AttachSelf -AttachSelfName 'DHCP Report' {
    EmailHeader {
        EmailFrom -Address 'MyEmail@evotec.pl'
        EmailTo -Addresses "MyOtherEmail@evotec.pl"
        EmailServer -Server 'smtp.office365.com' -UserName 'login@evotec.pl' -Password "$ENV:UserProfile\Desktop\Password-Evotec.txt" -PasswordAsSecure -PasswordFromFile -Port 587 -SSL
        EmailOptions -Priority High -DeliveryNotifications Never
        EmailSubject -Subject 'DHCP Report - Scope Utilization'
    }
    EmailBody {
        EmailTextBox -FontFamily 'Calibri' -Size 17 -TextDecoration underline -Color DarkSalmon -Alignment center {
            'Demonstration'
        }
        EmailText -LineBreak
        EmailTable -DataTable $Output {
            New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackGroundColor Red -Color White -Inline -ComparisonType number
            New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackGroundColor Yellow -Color Black -Inline -ComparisonType number
            New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackGroundColor Green -Color White -Inline -ComparisonType number
            New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackGroundColor Gray -Color White -Inline -ComparisonType string
            New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
            New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
            New-TableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray

        } -HideFooter
    }
} -Supress $false
```

[!\[HTML email preview of the DHCP scope utilization report with conditional formatting.\](/wp-content/uploads/2020/07/img_5f0b1221cd229.png)](/wp-content/uploads/2020/07/img_5f0b1221cd229.png)

Using the very same variable **$Output**, and using the same code that we used in **Out-HtmlView** to create a custom header with conditional formatting. Our **EmailHeader** contains information about server, recipients, and subject, while our body contains what we want to show in the email. We also used the **AttachSelf** parameter, which attaches the very same **HTML** that is displayed in email as an attachment. Why would I do this? Because if you do so, you get a modern version of the same report with **JavaScript** enabled.

[!\[Attached interactive DHCP report opened in a browser with export and search options.\](/wp-content/uploads/2020/07/img_5f0b12f987217.png)](/wp-content/uploads/2020/07/img_5f0b12f987217.png)

In other words, what's in **Email **is quickly available, but with the attachment, you get advanced features such as **filtering**, **export to Excel**, **CSV**, or **search**.

### 💡 DHCP Reporting – Full Code to Send Email

Full code to generate **DHCP Scopes** information and send pretty email takes just about **60 lines of code**.

```powershell
Import-Module PSWriteHTML

$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}

Email -AttachSelf -AttachSelfName 'DHCP Report' {
    EmailHeader {
        EmailFrom -Address 'myemail@evotec.pl'
        EmailTo -Addresses "myemail1@evotec.pl"
        EmailServer -Server 'smtp.office365.com' -UserName 'myemail@evotec.pl' -Password "$ENV:UserProfile\Desktop\Password-Evotec.txt" -PasswordAsSecure -PasswordFromFile -Port 587 -SSL
        EmailOptions -Priority High -DeliveryNotifications Never
        EmailSubject -Subject 'DHCP Report - Scope Utilization'
    }
    EmailBody {
        EmailTextBox -FontFamily 'Calibri' -Size 17 -TextDecoration underline -Color DarkSalmon -Alignment center {
            'Demonstration'
        }
        EmailText -LineBreak
        EmailTable -DataTable $Output {
            New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackGroundColor Red -Color White -Inline -ComparisonType number
            New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackGroundColor Yellow -Color Black -Inline -ComparisonType number
            New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackGroundColor Green -Color White -Inline -ComparisonType number
            New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackGroundColor Gray -Color White -Inline -ComparisonType string
            New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
            New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
            New-TableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray

        } -HideFooter
    }
} -Supress $false
```

Of course, thanks to having separate data gathering from data displaying, you could, for example, send an email only if certain conditions are met. Below is the same code just with renamed **New-TableCondition** to its alias **EmailTableCondition** and **New-TableHeader** to **EmailTableHeader**. It's a small change, but I do prefer to keep naming convention that way. It's just an alias, so only my preference.

```powershell
Import-Module PSWriteHTML

$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}

Email -AttachSelf -AttachSelfName 'DHCP Report' {
    EmailHeader {
        EmailFrom -Address 'myemail@evotec.pl'
        EmailTo -Addresses "myemail2@evotec.pl"
        EmailServer -Server 'smtp.office365.com' -Username 'myemail@evotec.pl' -Password "$ENV:UserProfile\Desktop\Password-Evotec.txt" -PasswordAsSecure -PasswordFromFile -Port 587 -SSL
        EmailOptions -Priority High -DeliveryNotifications Never
        EmailSubject -Subject 'DHCP Report - Scope Utilization'
    }
    EmailBody {
        EmailTextBox -FontFamily 'Calibri' -Size 17 -TextDecoration underline -Color DarkSalmon -Alignment center {
            'Demonstration'
        }
        EmailText -LineBreak
        EmailTable -DataTable $Output {
            EmailTableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
            EmailTableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
            EmailTableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
            EmailTableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
            EmailTableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
            EmailTableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
            EmailTableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray
        } -HideFooter
    }
} -Supress $false
```

### 💡 DHCP Reporting – PSWriteHTML Other Features

Now you know how to display **DHCP Scope Statistics** with **Out-HTMLView** or how to send an email with **Email**. But that's just a small part of **PSWriteHTML**. With minimal effort on your side, you can have multiple dynamic tables next to each other, on different tabs, with as many complications as you want.

[!\[PSWriteHTML page showing a DHCP report table beside a second table of running processes.\](/wp-content/uploads/2020/07/img_5f0b2cc5e53ca.png)](/wp-content/uploads/2020/07/img_5f0b2cc5e53ca.png)

I've taken the same **DHCP **output and added a list of processes running on the system. This is to show you that you can display any data next to each other without much preparation. And the code to do it is less than **20 lines of code**.

```powershell
New-HTML {
    New-HTMLSection -Invisible {
        New-HTMLSection -HeaderText 'DHCP Report' {
            New-HTMLTable -DataTable $Output {
                New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
                New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
                New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
                New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
                New-TableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray

            }
        }
        New-HTMLSection -HeaderText 'Some Processes' {
            New-HTMLTable -DataTable (Get-Process | Select-Object -First 15) {

            }
        }
    }
} -FilePath $Env:UserProfile\Desktop\DHCPReport.html -Online #-ShowHTML
```

Here's the full code with two tables.

```powershell
# Dynamically pulling the DHCP servers in a Active Directory domain
$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}

New-HTML {
    New-HTMLSection -Invisible {
        New-HTMLSection -HeaderText 'DHCP Report' {
            New-HTMLTable -DataTable $Output {
                New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
                New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
                New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackGroundColor BuddhaGold -Color White -FontWeight bold
                New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackGroundColor Gray
                New-TableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackGroundColor Gray

            }
        }
        New-HTMLSection -HeaderText 'Some Processes' {
            New-HTMLTable -DataTable (Get-Process | Select-Object -First 15) {

            }
        }
    }
} -FilePath $Env:UserProfile\Desktop\DHCPReport.html -Online -ShowHTML
```

Of course, you could do a lot more if you wanted to. Let's try to get other information from **DHCP** servers.

```powershell
# Dynamically pulling the DHCP servers in a Active Directory domain
$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}


New-HTML {
    New-HTMLTab -Name 'Summary' {
        New-HTMLSection -HeaderText 'All servers' {
            New-HTMLTable -DataTable $DHCP_Servers
        }
        foreach ($Server in $DHCP_Servers) {
            New-HTMLSection -Invisible {
                try {
                    $Database = Get-DhcpServerDatabase -ComputerName $Server.DnsName
                } catch {
                    continue
                }
                New-HTMLSection -HeaderText "Server $($Server.DnsName) - Database Information" {
                    New-HTMLTable -DataTable $Database
                }

                try {
                    $AuditLog = Get-DhcpServerAuditLog -ComputerName $Server.DnsName
                } catch {
                    continue
                }
                New-HTMLSection -HeaderText "Server $($Server.DnsName) - Audit Log" {
                    New-HTMLTable -DataTable $AuditLog
                }
            }
        }
    }
    New-HTMLTab -Name 'All DHCP Scopes' {
        New-HTMLSection -HeaderText 'DHCP Report' {
            New-HTMLTable -DataTable $Output {
                New-TableCondition -Name '% In Use' -Operator ge -Value 95 -BackgroundColor Red -Color White -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator ge -Value 80 -BackgroundColor Yellow -Color Black -Inline -ComparisonType number
                New-TableCondition -Name '% In Use' -Operator lt -Value 80 -BackgroundColor Green -Color White -Inline -ComparisonType number
                New-TableCondition -Name 'Scope State' -Operator eq -Value 'Inactive' -BackgroundColor Gray -Color White -Inline -ComparisonType string
                New-TableHeader -Title "DHCP Scope Statistics Report ($(Get-Date))" -Alignment center -BackgroundColor BuddhaGold -Color White -FontWeight bold
                New-TableHeader -Names 'DHCP Server', 'DHCP IP' -Title 'Server Information' -Color White -Alignment center -BackgroundColor Gray
                New-TableHeader -Names 'Subnet Mask', 'Start Range', 'End Range', 'Lease Duration' -Title 'Scope Configuration' -Color White -Alignment center -BackgroundColor Gray

            }
        }
    }
} -FilePath $Env:UserProfile\Desktop\DHCPReport.html -Online -ShowHTML
```

What that 80 lines code get you? **Custom HTML report** with two tabs, multiple tables, all with advanced options.

[!\[Tabbed PSWriteHTML report with a summary page for DHCP servers and scope information.\](/wp-content/uploads/2020/07/img_5f0b346c321b8.png)](/wp-content/uploads/2020/07/img_5f0b346c321b8.png)[!\[Second tab of the PSWriteHTML DHCP report showing all scopes with conditional formatting.\](/wp-content/uploads/2020/07/img_5f0b34b64ddde.png)](/wp-content/uploads/2020/07/img_5f0b34b64ddde.png)

Could it be cuter? Sure it could. I've spent very little time optimizing it looks. You could change colors, placement, or even add charts, gages, or other things.

### 💡 Earlier resources for PSWriteHTML, Dashimo, Statusimo or Emailimo as PowerShell Modules

If you liked what was presented here, feel free to read other related articles. Keep in mind that some are quite old, and a few things have changed. For example, there's no more **Emailimo** or **Dashimo**, as all those options are now part of **PSWriteHTML**. There's still separate Statusimo, but you don't need it to build something of your own.

- [Meet Statusimo – PowerShell generated Status Page](https://evotec.xyz/meet-statusimo-powershell-generated-status-page/)
- [Meet Dashimo – PowerShell Generated Dashboard](https://evotec.xyz/meet-dashimo-powershell-generated-dashboard/)
- [Dashimo – Easy Table Conditional Formatting and more](https://evotec.xyz/dashimo-easy-table-conditional-formatting-and-more/)
- [Out-HtmlView – HTML alternative to Out-GridView](https://evotec.xyz/out-htmlview-html-alternative-to-out-gridview/)
- [Meet Emailimo – New way to send pretty emails with PowerShell](https://evotec.xyz/meet-emailimo-new-way-to-send-pretty-emails-with-powershell/)
- [All your HTML Tables are belong to us](https://evotec.xyz/all-your-html-tables-are-belong-to-us/)
- [Sending HTML emails with PowerShell and zero HTML knowledge required](https://evotec.xyz/sending-html-emails-with-powershell-and-zero-html-knowledge-required/)
- [Dashimo (PSWriteHTML) – Charting, Icons and few other changes](https://evotec.xyz/dashimo-pswritehtml-charting-icons-and-few-other-changes/)
- [Working with HTML in PowerShell just got better](https://evotec.xyz/working-with-html-in-powershell-just-got-better/)
- [Comparing two or more objects visually in PowerShell (cross-platform)](https://evotec.xyz/comparing-two-or-more-objects-visually-in-powershell-cross-platform/)
- [Easy way to create diagrams using PowerShell and PSWriteHTML](https://evotec.xyz/easy-way-to-create-diagrams-using-powershell-and-pswritehtml/)
- [Nested Tabs, Diagram Updates, Diagram Events, Calendar Object and more in PSWriteHTML](https://evotec.xyz/nested-tabs-diagram-updates-diagram-events-calendar-object-and-more-in-pswritehtml/)
- [Emailimo merged into PSWriteHTML, IE support and no dependencies](https://evotec.xyz/emailimo-merged-into-pswritehtml-ie-support-and-no-dependencies/)

As mentioned earlier to simply get it up and running, just install it from **PowerShellGallery** and you're good.

```powershell
Install-Module PSWriteHTML -Force
```

If you want to explore other examples, I recommend running those available on [GitHub](https://github.com/EvotecIT/PSWriteHTML). A lot of stuff that [PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML) can do doesn't have documentation but is shown in **Examples**.

## Related Projects

Projects that align with this post's tags, categories, and content.

[All projects](/projects/)

Matching projects...

[Back to Blog](/blog)

## Related posts

- [Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module](/blog/unlocking-seamless-html-report-creation-harness-the-power-of-markdown-with-pswritehtml-powershell-module/)
- [Strengthening Password Security in Active Directory: A PowerShell-Powered Approach](/blog/strengthening-password-security-in-active-directory-a-powershell-powered-approach/)
- [PowerShell – Comparing advanced objects](/blog/powershell-comparing-advanced-objects/)

<!-- PowerForge markdown artifact sha256:8DB308F78F2C109CE26C4E7784A2E688C1DB76BC8BFFC608DC30768699B8D79B -->
