Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Created June 16, 2020 18:07
Show Gist options
  • Save pcgeek86/9f6b761d86af749757f7749bbd024c5e to your computer and use it in GitHub Desktop.
Save pcgeek86/9f6b761d86af749757f7749bbd024c5e to your computer and use it in GitHub Desktop.
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