Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Created Jun 16, 2020
Embed
What would you like to do?
Use PowerShell PSTypeNames and custom FormatData to limit default properties emitted from objects
$Object = [PSCustomObject]@{
FirstName = 'Trevor'
LastName = 'Sullivan'
}
$Object
$Object.PSObject.TypeNames.Add('Person')
$FormatData = @'
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>PersonTable</Name>
<ViewSelectedBy>
<TypeName>Person</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>FirstName</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
'@
$FormatData | Set-Content -Path Person.format.ps1xml
Update-FormatData -AppendPath Person.format.ps1xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment