Main | Contact | Blog | Documentation

PowerShell Framework

The project dedicated to empowering your PowerShell scripting.

Select-PSFObject

SYNOPSIS

Wrapper around Select-Object, extends property parameter.

SYNTAX

DefaultParameter (Default)

Select-PSFObject [-InputObject <PSObject>] [-Property <SelectParameter[]>] [-ExcludeProperty <String[]>]
 [-ExpandProperty <String>] [-Unique] [-Last <Int32>] [-First <Int32>] [-Skip <Int32>] [-Wait]
 [-ShowProperty <String[]>] [-ShowExcludeProperty <String[]>] [-TypeName <String>] [-KeepInputObject]
 [<CommonParameters>]

SkipLastParameter

Select-PSFObject [-InputObject <PSObject>] [-Property <SelectParameter[]>] [-ExcludeProperty <String[]>]
 [-ExpandProperty <String>] [-Unique] [-SkipLast <Int32>] [-ShowProperty <String[]>]
 [-ShowExcludeProperty <String[]>] [-TypeName <String>] [-KeepInputObject] [<CommonParameters>]

IndexParameter

Select-PSFObject [-InputObject <PSObject>] [-Unique] [-Wait] [-Index <Int32[]>] [-ShowProperty <String[]>]
 [-ShowExcludeProperty <String[]>] [-TypeName <String>] [-KeepInputObject] [<CommonParameters>]

DESCRIPTION

Wrapper around Select-Object, extends property parameter.

This function allows specifying in-line transformation of the properties specified without needing to use complex hashtables. For example, renaming a property becomes as simple as “Length as Size”

Also supported:

See the description of the Property parameter for an exhaustive list of legal notations for in-line transformations.

EXAMPLES

Example 1: Renaming a property

Get-ChildItem | Select-PSFObject Name, "Length as Size"

Selects the properties Name and Length, renaming Length to Size in the process.

_

Example 2: Converting type

Import-Csv .\file.csv | Select-PSFObject Name, "Length as Size to DbaSize"

Selects the properties Name and Length, renaming Length to Size and converting it to [DbaSize] (a userfriendly representation of size numbers contained in the dbatools module)

_

Example 3: Selecting from another object 1

$obj = [PSCustomObject]@{ Name = "Foo" }
Get-ChildItem | Select-PSFObject FullName, Length, "Name from obj"

Selects the properties FullName and Length from the input and the Name property from the object stored in $obj

_

Example 4: Selecting from another object 2

$list = @()
$list += [PSCustomObject]@{ Type = "Foo"; ID = 1 }
$list += [PSCustomObject]@{ Type = "Bar"; ID = 2 }
$obj | Select-PSFObject Name, "ID from list WHERE Type = Name"

This allows you to LEFT JOIN contents of another variable. Note that it can only do simple property-matching at this point.

It will select Name from the objects stored in $obj, and for each of those the ID Property on any object in $list that has a Type property of equal value as Name on the input.

_

Example 5: Naming and styling

Get-ChildItem | Select-PSFObject Name, Length, FullName, Used, LastWriteTime, Mode -TypeName MyType -ShowExcludeProperty Mode, Used

Lists all items in the current path, selects the properties specified (whether they exist or not) , then …

PARAMETERS

-InputObject

The object(s) to select from.

Type: PSObject
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Property

The properties to select.

Type: SelectParameter[]
Parameter Sets: DefaultParameter, SkipLastParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExcludeProperty

Properties to not list.

Type: String[]
Parameter Sets: DefaultParameter, SkipLastParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpandProperty

Properties to expand.

Type: String
Parameter Sets: DefaultParameter, SkipLastParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Unique

Do not list multiples of the same value.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Last

Select the last n items.

Type: Int32
Parameter Sets: DefaultParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-First

Select the first n items.

Type: Int32
Parameter Sets: DefaultParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Skip

Skip the first (or last if used with -Last) n items.

Type: Int32
Parameter Sets: DefaultParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-SkipLast

Skip the last n items.

Type: Int32
Parameter Sets: SkipLastParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Wait

Indicates that the cmdlet turns off optimization. Windows PowerShell runs commands in the order that they appear in the command pipeline and lets them generate all objects. By default, if you include a Select-PSFObject command with the First or Index parameters in a command pipeline, Windows PowerShell stops the command that generates the objects as soon as the selected number of objects is generated.

Type: SwitchParameter
Parameter Sets: DefaultParameter, IndexParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Index

Specifies an array of objects based on their index values. Enter the indexes in a comma-separated list.

Type: Int32[]
Parameter Sets: IndexParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ShowProperty

Only the specified properties will be shown by default. Supersedes ShowExcludeProperty

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ShowExcludeProperty

Hides the specified properties from the default display style of the output object. Is ignored if used together with ShowProperty.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-TypeName

Adds a typename to the selected object. Will automatically prefix the module.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-KeepInputObject

Keeps the original input object, adding new properties the select added without removing any. This allows you to use this command to add properties without losing the input object’s type.

Type: SwitchParameter
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 (http://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

NOTES

Online Documentation