Optimize-Object
SYNOPSIS
Optimize a PowerShell object by removing null or empty properties.
SYNTAX
DESCRIPTION
This function processes a PowerShell object (or a collection of objects) and removes properties based on the specified criteria. It supports removing null properties, empty properties, or both.
EXAMPLES
EXAMPLE 1
PS C:\> Optimize-Object -Object $Object -Remove "NullProperties" Returns the object with null properties removed.
EXAMPLE 2
PS C:\> Optimize-Object -Object $Object -Remove "EmptyProperties" Returns the object with empty properties removed.
EXAMPLE 3
PS C:\> Optimize-Object -Object $Object -Remove "NullAndEmptyProperties" Returns the object with both null and empty properties removed.
PARAMETERS
-Object
The PowerShell object (or collection of objects) to be optimized.
Type: PSObject
Parameter Sets: (All)
Aliases: PSObject, PSCustomObject
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
-Remove
Specifies the type of properties to remove. Valid values are: - NullAndEmptyProperties: Removes both null and empty properties. - NullProperties: Removes only null properties. - EmptyProperties: Removes only empty properties.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.