0

Good Morning all. I’m working on a script that updates a set of applications and I’m trying to make a HTML table for verification purposes. This comment is my framework

https://www.reddit.com/r/PowerShell/comments/3zai30/html_report_from_multiple_arrays/cyl9k47/?utm_source=share&utm_medium=ios_app&utm_name=iossmf&context=3

It works great for the most part. But it’s built off integers, so if I have an app fail to install/update, it messes up the placement of items. I’m looking for some insight into making it more of a static table so if an app fails to install/update it just is a blank line instead.

Function Get-Verification{
$Header = '<style>
    body {
        background-color: Gainsboro;
        font-family:      "Calibri";
    }

    table {
        border-width:     1px;
        border-style:     solid;
        border-color:     black;
        border-collapse:  collapse;
        width:            75%;
    }

    th {
        border-width:     1px;
        padding:          5px;
        border-style:     solid;
        border-color:     black;
        background-color: #98C6F3;
    }

    td {
        border-width:     1px;
        padding:          5px;
        border-style:     solid;
        border-color:     black;
        background-color: White;
    }

    tr {
        text-align:       left;
    }
</style>'

    
    [System.Collections.ArrayList]$SoftwareNames = @(
    "Notepad++",
    "PowerShell7",
    "RACTools",
    "Rufus",
    "RuTTY",
    "WinSCP",
    "WireShark",
    "Microsoft Edge",
    "Chrome Portable",
    "FireFox Portable",
    "NetBanner",
    "OVFTool",
    "PowerCLI",
    "VMRC",
    "Workstation",
    "Axway",
    "InstallRoot",
    "ActivClient",
    "90Meter",
    "Microsoft Office"
    )
    
    [System.Collections.ArrayList]$NewSWVersions = @(
    "$NotepadVersion",
    "$PowerShellVersion",
    "$RACToolsVersion",
    "$RufusVersion",
    "$RuTTYVersion",
    "$WinSCPVersion",
    "$WireSharkVersion",
    "$MSEdgeVersion", 
    "$ChromeVersion",
    "$FireFoxVersion",
    "$NetBannerVersion",
    "$OVFToolMsiVersion",
    "$PowerCLIVersion",
    "$VMRCVersion",
    "$WorkstationVersion",
    "$AxwayVersion",
    "$InstallRootMsi",
    "$ACVersion",
    "$90MVersion",
    "$Office" #Needs fixing
    )
    
    [System.Collections.ArrayList]$InstalledVersions = @(
    "$NotepadExe",
    "$PowerShellExe",
    "$RACToolsExe",
    "$RufusVersion",
    "$RuTTYExe",
    "$WinSCPExe",
    "$WireSharkExe",
    "$MSEdgeExe", 
    "$ChromeVersion",
    "$FireFoxVersion",
    "$NetBannerExe",
    "$OVFToolExe",
    "$PowerCLIModule",
    "$VMRCExe",
    "$WorkstationExe",
    "$AxwayExe",
    "$InstallRootExe",
    "$ACExe",
    "$90MExe",
    "$Office" #needs fixing
    )
    
    If($Class -eq "NIPR"){
        $SoftwareNames.Remove("90Meter")
        $NewSWVersions.Remove("$90MVersion")
        $InstalledVersions.Remove("$90MExe")
    }
    
    If($Class -eq "SIPR"){
        $SoftwareNames.Remove("ActivClient")
        $NewSWVersions.Remove("$ACVersion")
        $InstalledVersions.Remove("$ACExe")
    }   
    
    $i = 0
    
    $(
    While (
        @(
            $SoftwareNames[$i],
            $NewSWVersions[$i],
            $InstalledVersions[$i]
        ) -ne $null
    ) {
        $Properties = [ordered]@{
            "Software Names" = $SoftwareNames[$i]
            "Expected Version" = $NewSWVersions[$i]
            "Installed Version" = $InstalledVersions[$i]
        }
        New-Object psobject -Property $Properties
        $i++
    }
) | ConvertTo-Html -head $Header -PostContent "Report Run on $Date"| Out-File "App_Verification.htm"
invoke-item "App_Verification.htm"
    exit
    
}

The information I’m tabling is Application Name Expected Version Installed Version

They are all arrays with variables that pull the required information.

1 Answer 1

1

Use an ordered dictionary to store the information instead of separate arrays:

$software = [ordered]@{
    "Notepad++" = [pscustomobject]@{
        Application = "Notepad++"
        NewVersion = "$NotepadVersion"
        InstalledVersion = "$NotepadExe"
    }
    "PowerShell7" = [pscustomobject]@{
        Application = "PowerShell7"
        NewVersion = "$PowerShellVersion"
        InstalledVersion = "$PowerShellExe"
    }
    # ... and so on
}

Removing an application from the list then becomes:

If($Class -eq "NIPR"){
    # remove the whole object from the dictionary, no need to worry about multiple collections
    $software.Remove("90Meter")
}

And modifying the details of one is just a matter of referencing it by name and modifying the correct property:

$software['PowerShell7'].NewVersion = "new version goes here"

And since they're already objects now, exporting them to HTML is as easy as:

$software.Values |ConvertTo-Html ...
Sign up to request clarification or add additional context in comments.

3 Comments

I've changed everything over but when trying to run the last part. $Software.Values | ConvertTo-HTML I keep getting an error saying Missing '=' operator after key in hash literal.
That's a pretty good indicator that a = is missing either in the $software dictionary or one of the objects defined underneath.
I figured it out, had a closing bracket } below $Software.Values. corrected that and it works beautifully and I can't thank you enough!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.