Functions/Data/ConvertFrom-HTMLTable.ps1
Function ConvertFrom-HTMLTable { [CmdletBinding()] Param ( # HTML Table Object Reflection [Parameter(Mandatory=$true,ValueFromPipeline=$true)] $TableObj ) # Gather table elements in HTML Write-Progress -Activity "Gathering HTML Reflected Elements" -CurrentOperation "Body (1/3)" -PercentComplete (0) $BodyObj = $TableObj.childNodes[1] Write-Progress -Activity "Gathering HTML Reflected Elements" -CurrentOperation "Headers (2/3)" -PercentComplete (33) $HeaderObj = $BodyObj.childnodes[0] $H=0 $HeaderMap = Foreach ($header in $Headerobj.childnodes | where cellindex) { [pscustomobject]([ordered]@{ Name = $header.innertext.trim() Position = $header.cellindex }) $H++ } Write-Progress -Activity "Gathering HTML Reflected Elements" -CurrentOperation "Rows (3/3)" -PercentComplete (66) $RowObjs = $BodyObj.childNodes | where rowindex Write-Progress -Activity "Gathering HTML Reflected Elements" -Completed # Create Array from Table $I=0 $Data = foreach ($RowObj in $RowObjs) { Write-Progress -Activity "Building Array From Table" -CurrentOperation "ROW: ($I/$($rowobjs.count))" -PercentComplete ($I/$RowObjs.count*100) $RowHash = [ordered]@{} $II = 0 foreach ($header in $headermap) { $Value = $RowObj.cells[$header.position].innerText $VTrim = if($value){$value.trim()}else{$null} $RowHash.add($header.name,$VTrim) $II++ } [pscustomobject]($RowHash) $I++ } Write-Progress -Activity "Building Array From Table" -Completed # Express Data $DATA } |