Created
June 16, 2020 18:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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