Using MarkdownPS PowerShell module this is a simple cmdlet that
- Tests the state of the computer using PowerShell’s
Test-Connection
cmdlet - Depending on the outcome it generates a badge in markdown with red or green state.
function New-ComputerBadge {
param (
[Parameter(Mandatory=$true)]
[string]
$Computer
)
try
{
if(Test-Connection $Computer -Quiet)
{
$color="green"
$status="Live"
}
else
{
$color="red"
$status="Not Live"
}
New-MDImage -Subject $Computer -Status $status -Color $color
}
catch
{
Write-Error $_
New-MDImage -Subject "Badge" -Status "Error" -Color red
}
}
Example
New-ComputerBadge -Computer "EXAMPLE"
renders the following markdown
![](https://img.shields.io/badge/EXAMPLE-Live-green.svg)
![](https://img.shields.io/badge/EXAMPLE-Not%20Live-red.svg)
Leave a Comment