File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 3131 .> { new ScriptBlock 'Get-Command'}
3232. EXAMPLE
3333 .> { (new PowerShell).AddScript("Get-Command").Invoke() }
34+ . EXAMPLE
35+ .> { new 'https://schema.org/Thing' }
3436#>
3537[ValidateScript ({
3638 $CommandAst = $_
@@ -46,15 +48,15 @@ process {
4648 $null , $newTypeName , $newArgs = $CommandAst.CommandElements
4749 $maybeGeneric = $false
4850 $propertiesToCreate = @ ()
49-
51+ $newTypeNameAst = $newTypeName
5052 $newTypeName =
5153 # Non-generic types will be a bareword constant
5254 if ($newTypeName.Value ) {
5355 $newTypeName.Value
5456 }
5557 elseif ($newTypeName -is [Management.Automation.Language.HashtableAst ]) {
5658 $propertiesToCreate += $newTypeName
57- }
59+ }
5860 else {
5961 # generic types will be an ArrayLiteralAst
6062 $maybeGeneric = $true
@@ -135,7 +137,14 @@ process {
135137 }
136138 } elseif ($propertiesToCreate.Count -eq 1 -and -not $newTypeName ) {
137139 " [PSCustomObject][Ordered]$propertiesToCreate "
138- } else {
140+ } elseif ($newTypeNameAst -is [Management.Automation.Language.StringConstantExpressionAst ]) {
141+ if ($propertiesToCreate ) {
142+ " [PSCustomObject]([Ordered]@{PSTypeName=$newTypeNameAst } + ([Ordered]$propertiesToCreate ))"
143+ } else {
144+ " [PSCustomObject][Ordered]@{PSTypeName=$newTypeNameAst }"
145+ }
146+ }
147+ else {
139148 Write-Error " Unknown type '$newTypeName '"
140149 return
141150 }
You can’t perform that action at this time.
0 commit comments