# Cmdlet Out-GridView doesn't display data

**URL:** <https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004>\
**Category:** PowerShell Help\
**Created:** [March 30, 2023, 5:50am UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004 "2023-03-30T05:50:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![drew](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@drew](https://forums.powershell.org/u/drew)\
**Post date:** [March 30, 2023, 5:50am UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/1 "2023-03-30T05:50:02Z")

</div>

Hello everybody!

I’m really confused facing such a problem:  
I get a number of similar web-pages from a web-site, pull out a table from them and create an array of objects with properties corresponding with data from that tables. At the end of a script I’d like to output the array via Out-GridView but it outputs just the property that I programmatically set in the script. All properties that were taken from web-site are empty despite I can see them in a console output. The property names are displayed in the column headers correctly, but the property values seem to be empty.  
Here is my script for you can check this behavior yourself:

```auto
$bdus = [regex]::Matches((Get-Clipboard),'BDU:\d{4}-\d{5}').value
$Result = @()
$bdus | `
    %{  
        $ht = [ordered]@{}
        $ht.Name = $_
        $url = "https://bdu.fstec.ru/vul/{0}" -f ($_ -replace 'BDU:(.+)','$1')
        $wpage = Invoke-WebRequest $url
        $vul = $wpage.ParsedHtml.GetElementsByTagName('TABLE')[0]
        $vul.rows | %{$ht.($_.Cells[0].InnerText) = $_.Cells[1].InnerText}
        $Result += New-Object -TypeName:psobject -Property:$ht
     }
$Result | Out-GridView

```

I’ve thought this was caused by the fact that property names are in quote marks in cyrilic with spaces but not. A simple test with similar data works fine! The next assumption was that the problem in codepages: web-site is utf-8 and system locale is windows-1251, so I tried to convert encodings:

```auto
$encodingclass = [System.Text.Encoding]
$wpencoding = $encodingclass::GetEncoding('utf-8')
$OutEncoding = $encodingclass::GetEncoding('windows-1251')
$bdus = [regex]::Matches((Get-Clipboard),'BDU:\d{4}-\d{5}').value
$Result = @()
$bdus | `
    %{  
        $ht = [ordered]@{}
        $ht.Name = $_
        $url = "https://bdu.fstec.ru/vul/{0}" -f ($_ -replace 'BDU:(.+)','$1')
        $wpage = Invoke-WebRequest $url
        $vul = $wpage.ParsedHtml.GetElementsByTagName('TABLE')[0]
        $vul.rows | %{$ht.($_.Cells[0].InnerText) = $OutEncoding.getstring($encodingclass::Convert($wpencoding, $OutEncoding, $OutEncoding.GetBytes($_.Cells[1].InnerText)))}
        $Result += New-Object -TypeName:psobject -Property:$ht
     }
$Result | Out-GridView

```

But result is the same((((  
Please do help!!! What am I doing wrong???

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [March 30, 2023, 2:17pm UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/2 "2023-03-30T14:17:44Z")

</div>

Without a source or even a sample of it, I’m not sure we can offer much meaningful advice. One thing that sticks out is the old, terrible practice of

```auto
$array = @()
$array += something

```

This is extremely costly especially in larger data sets as it recreates the array every time you add to it. It’s best to just let Powershell collect the items for you

```auto
$array = some loop or code that outputs objects

```

Also, the pipe character is a natural line break, no need for a backtick. It’s also a bad habit to use backticks for formatting.

---

<div class="post-metadata">

**Author:** ![ZaMotH](https://avatars.discourse-cdn.com/v4/letter/z/258eb7/32.png) [@ZaMotH](https://forums.powershell.org/u/ZaMotH)\
**Post date:** [March 30, 2023, 2:50pm UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/3 "2023-03-30T14:50:19Z")

</div>

I wrote this script … a long time ago. I would probably rewrite it totally differently today.

But this should convert tables to PsObject.

```auto
function ConvertFrom-HtmlTable {
	param(
		[Parameter(Mandatory = $true)][Microsoft.PowerShell.Commands.HtmlWebResponseObject]$WebRequest,
		[Parameter(Mandatory = $true)][int]$TableNumber=1
	)

	$tables = @($WebRequest.ParsedHtml.getElementsByTagName("TABLE"))
	$table = $tables[$TableNumber]
	$titles = @()
	$rows = @($table.Rows)

	## Go through all of the rows in the table
	$Result = @()
	foreach($row in $rows) {
		Write-Progress -Activity "Converting HTML Table to Data" -Status " > Converting ..." -PercentComplete (100 * $rows.IndexOf($row) / $rows.count)
		$cells = @($row.Cells)
		if($cells[0].tagName -eq "TH") {
			$titles = @($cells | % { ("" + $_.InnerText).Trim() })
			continue
		}
		if(!$titles) { $titles = @(1..($cells.Count + 2) | % { "P$_" }) }
		$resultObject = [Ordered] @{}
		for($counter = 0; $counter -lt $cells.Count; $counter++) {
			$title = $titles[$counter]
			if(!$title) { continue }
			$resultObject[$title] = ("" + $cells[$counter].InnerText).Trim()
		}
		$Result += [PSCustomObject]$resultObject
	}
	return $Result

}

```

You can have a try, it may work … or not

---

<div class="post-metadata">

**Author:** ![drew](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@drew](https://forums.powershell.org/u/drew)\
**Post date:** [March 31, 2023, 6:22am UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/5 "2023-03-31T06:22:13Z")

</div>

> [@krzydoug](#):
>
> Without a source or even a sample of it, I’m not sure we can offer much meaningful advice. One thing that sticks out is the old, terrible practice of
> 
> ```auto
> $array = @()
> $array += something
> 
> ```
> 
> This is extremely costly especially in larger data sets as it recreates the array every time you add to it. It’s best to just let Powershell collect the items for you
> 
> ```auto
> $array = some loop or code that outputs objects
> 
> ```
> 
> Also, the pipe character is a natural line break, no need for a backtick. It’s also a bad habit to use backticks for formatting.

Hello!  
You’re quite sure! I’ve didn’t mention that you can’t get MY clipboard))) My bad…  
The user ZaMotH ansewered below with his own script that gave me a thought of what was wrong in mine one. If you wish, take a look at my answer to his post where I’ll describe the solution and my problem’s origins.  
Anyway, thank you very much for your attention and answer! Special thanks for tip about backtick & a pipeline character – without backticks the sourcecode looks much elegant!  
About arrays – quite whrite again, but it’s a deal of habbit: old school)))

---

<div class="post-metadata">

**Author:** ![drew](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@drew](https://forums.powershell.org/u/drew)\
**Post date:** [March 31, 2023, 6:42am UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/6 "2023-03-31T06:42:17Z")

</div>

Hello!  
Thanks a lot for your help!  
Your script really helped me! I’ve noticed the only but principal difference between our sourcecodes: I didn’t trimmed the strings from the web site that I’ve made an object’s properties. I’ve added this here:

> [@drew](#):
>
> ```auto
> $vul = $wpage.ParsedHtml.GetElementsByTagName('TABLE')[0]
> $vul.rows | %{$ht.($_.Cells[0].InnerText.Trim()) = $_.Cells[1].InnerText}
> $Result += New-Object -TypeName:psobject -Property:$ht
> 
> ```

and everything began to work fine! Just as wanted & needed)))  
A funny thing is that I’ve noticed a whitespace at the end of property names but unfortunately have made little of it((( Live and learn)))

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/cmdlet-out-gridview-doesnt-display-data/22004/7 "2024-05-16T20:14:59Z")

</div>


