Public/Remove-DefaultPropertySetProperty.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function Remove-DefaultPropertySetProperty {
    <#
    .SYNOPSIS
    Removes Properties from the Default Display Property Set of an Object.
 
    .DESCRIPTION
    The Remove-DefaultPropertySetProperty function removes Properties from the
    Default Display Property Set of a PSCustomObject or collection of PSCustomObjects.
 
    .PARAMETER Object
    PSCustomObject(s) with an existing Default Display Property Set.
 
    .PARAMETER Property
    The name of the properties to be removed from the Default Display Property Set.
 
    .EXAMPLE
    Remove-DefaultPropertySetProperty -Object $DemoObject1 -Property 'Name', 'Date'
 
    This command removes the properties 'Name' and 'Date' from $DemoObject1's Default
    Display Property Set.
 
    .EXAMPLE
    $DemoObject1, $DemoObject2 | Remove-DefaultPropertySetProperty -Property 'Date'
 
    This command takes two objects as input from the pipeline and removes the property
    'Date' from both of their Default Display Property Sets.
 
    .LINK
    https://github.com/Windos/DefaultPropertySetter
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory,
                   ValueFromPipeline)]
        [PSCustomObject[]] $Object,

        [Parameter(Mandatory)]
        [String[]] $Property
    )

    Begin {}

    Process {
        foreach ($Obj in $Object) {
            foreach ($Prop in $Property) {
                $null = $Obj.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames.Remove($Prop)
            }
        }
    }

    End {}
}