# Why can not I get Select-Object to work on hashtable right

**URL:** <https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739>\
**Category:** PowerShell Help\
**Created:** [August 21, 2015, 11:47am UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739 "2015-08-21T11:47:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregory-suvalian](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@gregory-suvalian](https://forums.powershell.org/u/gregory-suvalian)\
**Post date:** [August 21, 2015, 11:47am UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/1 "2015-08-21T11:47:05Z")

</div>

I have hashtable which is returned from execution of remote command. Yet when I issue Select-Object command it does not pull those properties out. It does work on some objects and not on others (I execute the same script on range of computers). And I can not figure out what the difference between those.

`
PS C:\> $b.GetType()
IsPublic IsSerial Name BaseType

True True Hashtable System.Object
PS C:&gt; $b.Keys
LogNameForSource
MachineName
SourceExists
PS C:&gt; $b.Values
Application
DNVAPPSVC1
True
PS C:&gt; $b | Select-Object -Property LogNameForSource, MachineName, SourceExists | ft -AutoSize
LogNameForSource MachineName SourceExists

`

---

<div class="post-metadata">

**Author:** ![gregory-suvalian](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@gregory-suvalian](https://forums.powershell.org/u/gregory-suvalian)\
**Post date:** [August 21, 2015, 11:54am UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/2 "2015-08-21T11:54:36Z")

</div>

I found what the difference is - one some computers using Invoke-Command returns PSCustomObject and on others it returns HashTable code is below

`
$temp = {$result= [pscustomobject]@{"MachineName" = $env:ComputerName; "SourceExists" = [bool] $false;"LogNameForSource"=""}
	if ([System.Diagnostics.EventLog]::SourceExists('dcom'))
	{
		$result.SourceExists = $true
		$result.LogNameForSource = [System.Diagnostics.EventLog]::LogNameFromSourceName("dcom", ".")
	}
	return $result
	}
`

`$a = Invoke-Command -ScriptBlock $temp -ComputerName Server1
PS C:&gt; $a.GetType().Name
PSCustomObject
$a = Invoke-Command -ScriptBlock $temp -ComputerName Server2
PS C:&gt; $a.GetType().Name
Hashtable
`

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 21, 2015, 11:35pm UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/3 "2015-08-21T23:35:33Z")

</div>

And a hash table only has Key and Value properties. You can’t select just a particular key using Select-Object.

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [August 22, 2015, 1:41am UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/4 "2015-08-22T01:41:40Z")

</div>

GS,

Check out the official documentation regarding hash tables for examples:

[https://technet.microsoft.com/en-us/library/Hh847780.aspx](https://technet.microsoft.com/en-us/library/Hh847780.aspx)

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [August 23, 2015, 7:14pm UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/5 "2015-08-23T19:14:28Z")

</div>

**GS** , on these computers you probably does not have latest PS  
`
PS C:\Users> $psversiontable
Name Value`

`

[…]
PSVersion 2.0
[…]
PS C:\Users> [pscustomobject]@{aaa=‘aaaa’;bbb=‘bbbb’}
Name Value

bbb bbbb
aaa aaaa
PS C:\Users> ([pscustomobject]@{aaa=‘aaaa’;bbb=‘bbbb’}).gettype()
IsPublic IsSerial Name BaseType

`

`True True Hashtable System.Object
`  
[pscustomobject] was implemented on v3+

---

<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:44pm UTC](https://forums.powershell.org/t/why-can-not-i-get-select-object-to-work-on-hashtable-right/4739/6 "2024-05-16T20:44:52Z")

</div>

Closed on May 16, 2024, 8:44pm UTC


