mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-08-03 15:37:56 +00:00
45 lines
1.5 KiB
PowerShell
45 lines
1.5 KiB
PowerShell
function ConvertTo-TableFormat {
|
|
<#
|
|
.SYNOPSIS
|
|
Rebuild an object based on the Format Data for the object.
|
|
.DESCRIPTION
|
|
Allows an object to be rebuilt based on the view data for the object. Uses Select-Object to create a new PSCustomObject.
|
|
#>
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(ValueFromPipeline)]
|
|
[Object]$InputObject
|
|
)
|
|
begin {
|
|
$isFirst = $true
|
|
}
|
|
process {
|
|
$format = if ($isFirst) {
|
|
$formatData = Get-FormatData -TypeName $InputObject.PSTypeNames | Select-Object -First 1
|
|
if ($formatData) {
|
|
$viewDefinition = $formatData.FormatViewDefinition | Where-Object Control -match 'TableControl'
|
|
|
|
for ($i = 0; $i -lt $viewDefinition.Control.Headers.Count; $i++) {
|
|
$name = $viewDefinition.Control.Headers[$i].Label
|
|
|
|
$displayEntry = $viewDefinition.Control.Rows.Columns[$i].DisplayEntry
|
|
if (-not $name) {
|
|
$name = $displayEntry.Value
|
|
}
|
|
|
|
$expression = switch ($displayEntry.ValueType) {
|
|
'Property' { $displayEntry.Value }
|
|
'ScriptBlock' { [ScriptBlock]::Create($displayEntry.Value) }
|
|
}
|
|
|
|
@{ Name = $name; Expression = $expression }
|
|
}
|
|
}
|
|
}
|
|
if ($format) {
|
|
$InputObject | Select-Object -Property $format
|
|
} else {
|
|
$InputObject
|
|
}
|
|
}
|
|
} |