internal/Select-DefaultField.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Function Select-DefaultField
{
    <#
    
    This command enables us to send full on objects to the pipeline without the user seeing it
    
    See it in action in Get-DbaSnapshot and Remove-DbaDatabaseSnapshot
    
    this is all from boe, thanks boe!
    https://learn-powershell.net/2013/08/03/quick-hits-set-the-default-property-display-in-powershell-on-custom-objects/
    
    #>

    
    [CmdletBinding()]
    param (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [pscustomobject]$InputObject,
        [parameter(Mandatory = $true)]
        [string[]]$Property
    )
    
    $inputobject.PSObject.TypeNames.Insert(0, 'dbatools.customobject')
    $defaultset = New-Object System.Management.Automation.PSPropertySet('DefaultDisplayPropertySet', [string[]]$Property)
    $standardmembers = [System.Management.Automation.PSMemberInfo[]]@($defaultset)
    $inputobject | Add-Member MemberSet PSStandardMembers $standardmembers
    $inputobject
}