# Type Accelerator?

**URL:** https://forums.powershell.org/t/type-accelerator/14129
**Category:** PowerShell Help
**Created:** [April 9, 2020, 2:11pm UTC](https://forums.powershell.org/t/type-accelerator/14129 "2020-04-09T14:11:08Z")
**Posts on this page:** 9
**Page:** 1

<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: [April 9, 2020, 2:11pm UTC](https://forums.powershell.org/t/type-accelerator/14129/1 "2020-04-09T14:11:08Z")

</div>

I’ve asked this question to colleagues and of course google. I’m assuming it has something to do with it being a type accelerator, but from what I’ve read my understanding is that type accelerators help you to not have to type the full .Net type. So why can’t I do it the long way? I’m looking for actual technical reasons, not “because Bruce Payette said so” or the like. 🙂

This

```
$var = [System.Management.Automation.PSCustomObject]@{
    Name = 'test'
    Admin = $true
}
```

results in error

```
Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Management.Automation.PSCustomObject".
```

But this

```
$var = [PSCustomObject]@{
    Name = 'test'
    Admin = $true
}
$var | gm
```

works just fine, get-member shows

```
$var | gm

TypeName: System.Management.Automation.PSCustomObject
```

And then lastly

```
$var = @{
    Name = 'test'
    Admin = $true
}
```

Is just a hash table

```
$var | gm

TypeName: System.Collections.Hashtable
```

I know it’s probably something dumb and I’m an idiot for asking. But it’s always bugged me.

---

<div class="post-metadata">

### Author: ![juancrl](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@juancrl](https://forums.powershell.org/u/juancrl)
#### Post date: [April 10, 2020, 3:14am UTC](https://forums.powershell.org/t/type-accelerator/14129/2 "2020-04-10T03:14:02Z")

</div>

Interesting topic !

I’ve tried your cast inside a Trace-Command block… and getting no more useful info.

I’ve assumed also it might be a parser thing (maybe Bruce 🙂 checked for this specific cast only for the type accelerator name, and not for the full base type, or the System namespace but not System.Management.Automation, or whatever …)

But it is not the parser. It seems something inside .NET, as doing it in two steps also fails the same way :

`
$var1 = @{
Name = ‘test’
Admin = $true
} # OK
$Var2 = [System.Management.Automation.PSCustomObject]$Var1 # Same error
`

BTW,

`
$var -IS [System.management.automation.pscustomobject] # returns $true
`

Next step would be checking the PowerShell source code…

---

<div class="post-metadata">

### Author: ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)
#### Post date: [April 10, 2020, 7:14am UTC](https://forums.powershell.org/t/type-accelerator/14129/3 "2020-04-10T07:14:03Z")

</div>

Great question. I think somehow it’s the equivalent of:

```
new-object -typename psobject -property @{name='test'}
```

But even this still results in a hashtable:

```
[psobject]::new(@{name='test'})

Name Value
---- -----
name test
```

Get type accelerator: [Powershell: Everything you wanted to know about PSCustomObject](https://powershellexplained.com/2016-10-28-powershell-everything-you-wanted-to-know-about-pscustomobject/)

```
[psobject].Assembly.GetType(“System.Management.Automation.TypeAccelerators”)::get | 
  % { $_.['pscustomobject'] } 

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True PSObject System.Object
```

---

<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: [April 10, 2020, 7:29am UTC](https://forums.powershell.org/t/type-accelerator/14129/4 "2020-04-10T07:29:22Z")

</div>

Dang it, Bruce! Thanks for chiming in guys, I’ve already learned a couple of things from you both.

---

<div class="post-metadata">

### Author: ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)
#### Post date: [April 10, 2020, 7:45am UTC](https://forums.powershell.org/t/type-accelerator/14129/5 "2020-04-10T07:45:01Z")

</div>

I’ve been digging around. It might just be a bug or non-optimal behavior that would require a breaking change? For example: [[System.Management.Automation.PSCustomObject] weirdness · Issue #2295 · PowerShell/PowerShell · GitHub](https://github.com/PowerShell/PowerShell/issues/2295)

---

<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: [April 10, 2020, 8:11am UTC](https://forums.powershell.org/t/type-accelerator/14129/6 "2020-04-10T08:11:40Z")

</div>

That is exactly the issue, it tabbed completed and didn’t work. I am curious (and annoyed) with my favorite search engine that I wasn’t able to locate this. Thank you so much for spending the time to find this.

---

<div class="post-metadata">

### Author: ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)
#### Post date: [April 10, 2020, 8:16am UTC](https://forums.powershell.org/t/type-accelerator/14129/7 "2020-04-10T08:16:34Z")

</div>

Looks like the magic is in the source code: [powershell - How come I can create objects with [pscustomobject] but not [System.Management.Automation.PSCustomObject]? - Stack Overflow](https://stackoverflow.com/a/61141536/6654942)

---

<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: [April 10, 2020, 8:20am UTC](https://forums.powershell.org/t/type-accelerator/14129/8 "2020-04-10T08:20:45Z")

</div>

Absolutely. I love the comments.

> // We can't use the normal PSConvertBinder because it is strongly typed, and we // play some funny games with the PSCustomObject type (externally, it's just an // alias for PSObject, internally we do other stuff with it.)

---

<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:29pm UTC](https://forums.powershell.org/t/type-accelerator/14129/9 "2024-05-16T20:29:54Z")

</div>


