< Back

Select-DbaObject

Mon Jan 13, 2020 1:40 pm

NAME Select-DbaObject



SYNOPSIS

Wrapper around Select-Object, extends property parameter.





SYNTAX

Select-DbaObject [-InputObject <PSObject>] [-Property <SelectParameter[]>] [-ExcludeProperty <String[]>]

[-ExpandProperty <String>] [-Unique] [-Last <Int32>] [-First <Int32>] [-Skip <Int32>] [-Wait] [-ShowProperty

<String[]>] [-ShowExcludeProperty <String[]>] [-TypeName <String>] [-KeepInputObject] [-Alias

<SelectAliasParameter[]>] [-ScriptMethod <SelectScriptMethodParameter[]>] [-ScriptProperty

<SelectScriptPropertyParameter[]>] [<CommonParameters>]



Select-DbaObject [-InputObject <PSObject>] [-Property <SelectParameter[]>] [-ExcludeProperty <String[]>]

[-ExpandProperty <String>] [-Unique] [-SkipLast <Int32>] [-ShowProperty <String[]>] [-ShowExcludeProperty

<String[]>] [-TypeName <String>] [-KeepInputObject] [-Alias <SelectAliasParameter[]>] [-ScriptMethod

<SelectScriptMethodParameter[]>] [-ScriptProperty <SelectScriptPropertyParameter[]>] [<CommonParameters>]



Select-DbaObject [-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:



- Specifying a typename



- Picking the default display properties



- Adding to an existing object without destroying its type



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

transformations.





PARAMETERS

-InputObject <PSObject>

The object(s) to select from.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



-Property <SelectParameter[]>

The properties to select. - Supports hashtables, which will be passed through to Select-Object.



- Supports renaming as it is possible in SQL: "Length AS Size" will select the Length property but rename it

to size.



- Supports casting to a specified type: "Address to IPAddress" or "Length to int".



Uses PowerShell type-conversion. - Supports parsing numbers to sizes: "Length size GB:2" Converts numeric

input (presumed to be bytes) to gigabyte with two decimals. Also supports toggling on Unit descriptors by

adding another element: "Length size GB:2:1" - Supports selecting properties from objects in other variables:

"ComputerName from VarName" (Will insert the property 'ComputerName' from variable $VarName)



- Supports filtering when selecting from outside objects: "ComputerName from VarName where ObjectId = Id"

(Will insert the property 'ComputerName' from the object in variable $VarName, whose ObjectId property is

equal to the inputs Id property)



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeProperty <String[]>

Properties to not list.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ExpandProperty <String>

Properties to expand.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Unique [<SwitchParameter>]

Do not list multiples of the same value.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Last <Int32>

Select the last n items.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-First <Int32>

Select the first n items.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Skip <Int32>

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



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-SkipLast <Int32>

Skip the last n items.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Wait [<SwitchParameter>]

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-DbaObject 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.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Index <Int32[]>

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



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ShowProperty <String[]>

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



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ShowExcludeProperty <String[]>

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

together with ShowProperty.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-TypeName <String>

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



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-KeepInputObject [<SwitchParameter>]

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.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Alias <SelectAliasParameter[]>

Create an alias property. This can be in simple SQL notation, such as "Length as Size" or a hashtable with the

alias name being the key and the referenced property being the value.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ScriptMethod <SelectScriptMethodParameter[]>

Add script methods to the object. This can be done using either:



- String syntax 'GetDouble => $this.Length * 2'



- Hashtable defining any number of methods, with the name being the key and the scriptblock being the value.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ScriptProperty <SelectScriptPropertyParameter[]>

Add script properties to the object. This parameter takes a hashtable that can be either simply Name -->

Scriptblock binding (for readonly properties) or Name --> Hashtable binding, with the inner hashtable

containing two keys: get & set. Each pointing at their respective scriptblock.



-ScriptProperty @{



DoubleSize = { $this.Length * 2}



MegaSize = @{



get = { $this.Length * 10 }



set = { $this.Length = $_ / 10 }



}



}



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES









---------------- Example 1: Renaming a property ----------------



Get-ChildItem | Select-DbaObject 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-DbaObject 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-DbaObject 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-DbaObject 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-DbaObject 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 ...



- Sets the name to "MyType"



- Hides the properties "Mode" and "Used" from the default display set, causing them to be hidden from default view



RELATED LINKS

Online Documentation https://dbatools.io/Select-DbaObject