Private/Kinds/Startup.ps1

# The Startup Kind: what runs before the Technician's Customer gets to work.
#
# The Finding is a count, which is all a first-level Technician needs to act on. The
# Section beneath it is the list, which is what second level needs to say which entry to
# remove - and which is why the list travels with the Report rather than being something
# to go back to the machine for.

function Get-StartupData {
    [CmdletBinding()]
    [OutputType([psobject])]
    param([hashtable]$Parameters = @{})

    $entries   = @()
    $available = $true
    try {
        $entries = @(Get-CimInstance Win32_StartupCommand -ErrorAction Stop | ForEach-Object {
            [pscustomobject]@{
                Name     = "$($_.Name)"
                Command  = "$($_.Command)"
                Location = "$($_.Location)"
                User     = "$($_.User)"
            }
        })
    }
    catch { $available = $false }

    [pscustomobject]@{
        PSTypeName = 'Gutcheck.Data.Startup'
        Available  = $available
        Entries    = $entries
    }
}

function ConvertTo-StartupFinding {
    [CmdletBinding()]
    [OutputType([psobject])]
    param(
        [AllowNull()]$Data,
        [hashtable]$Parameters = @{}
    )

    $warnAbove = Get-Parameter $Parameters 'StartupEntryWarnAbove' 15
    $failAbove = Get-Parameter $Parameters 'StartupEntryFailAbove' ([double]::MaxValue)

    if (-not (Get-DataProperty $Data 'Available')) {
        return New-UnavailableFinding -Category Startup -Check (Get-Text 'Check.Startup.StartupEntries') `
            -Hint (Get-Text 'Hint.Startup.WindowsDidNotEnumerateIts')
    }

    $entries = Get-DataCollection $Data 'Entries'

    New-Finding -Category Startup -Check (Get-Text 'Check.Startup.StartupEntries') `
        -Severity (Get-Severity $entries.Count $warnAbove $failAbove) -Value $entries.Count `
        -Hint (Get-Text 'Hint.Startup.ManyAutostartProgramsReviewIn')
}

function ConvertTo-StartupSection {
    [CmdletBinding()]
    [OutputType([psobject])]
    param([AllowNull()]$Data)

    New-Section -Title (Get-Text 'Title.Startup.StartupEntries') -Row (Get-DataCollection $Data 'Entries')
}