Contenidos
Convertir Hashtables to [PSCustomObject]
1 2 3 4 |
[pscustomobject]@{ nombre = 'Marta' apellido = 'Lirón' } |
Using Select-Object cmdlets
1 |
'' | Select-Object @{n='nombre';e={'Marta'}},@{n='apellido';e={'Lirón'}} |
Using New-Object and Add-Member
1 2 3 4 |
$objeto = New-Object -TypeName psobject $objeto | Add-Member -MemberType NoteProperty -Name nombre -Value 'Marta' $objeto | Add-Member -MemberType NoteProperty -Name apellido -Value 'Lirón' $objeto | Add-Member -MemberType ScriptMethod -Name "GetName" -Value {$this.nombre +' '+$this.apellido} |
Using New-Object and hashtables
1 2 3 4 5 6 |
$properties = @{ firstname = 'Marta' lastname = 'Lirón' } $object = New-Object psobject -Property $properties; $object |