Thor Logo dbatools

Select-DbaObject

View Source
Friedrich Weinmann (@FredWeinmann)
Windows, Linux, macOS

Synopsis

Wrapper around Select-Object, extends property parameter.

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.

Syntax

Select-DbaObject
    [-Property <DbaSelectParameter[]>]
    [-Alias <SelectAliasParameter[]>]
    [-ScriptProperty <SelectScriptPropertyParameter[]>]
    [-ScriptMethod <SelectScriptMethodParameter[]>]
    [-InputObject ]
    [-ExcludeProperty <string[]>]
    [-ExpandProperty ]
    -Unique
    [-Last ]
    [-First ]
    [-Skip ]
    -Wait
    [-ShowProperty <string[]>]
    [-ShowExcludeProperty <string[]>]
    [-TypeName ]
    -KeepInputObject
    []            

Select-DbaObject
    [-Property <DbaSelectParameter[]>]
    [-Alias <SelectAliasParameter[]>]
    [-ScriptProperty <SelectScriptPropertyParameter[]>]
    [-ScriptMethod <SelectScriptMethodParameter[]>]
    [-InputObject ]
    [-ExcludeProperty <string[]>]
    [-ExpandProperty ]
    -Unique
    [-SkipLast ]
    [-ShowProperty <string[]>]
    [-ShowExcludeProperty <string[]>]
    [-TypeName ]
    -KeepInputObject
    []            

Select-DbaObject
    [-InputObject ]
    -Unique
    -Wait
    [-Index <int[]>]
    [-ShowProperty <string[]>]
    [-ShowExcludeProperty <string[]>]
    [-TypeName ]
    -KeepInputObject
    []

 

Examples

 

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

Optional Parameters

-Alias
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ExcludeProperty
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ExpandProperty
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-First
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Index
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-InputObject
PropertyValue
Alias
RequiredFalse
Pipelinetrue (ByValue)
Default Value
-KeepInputObject
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Last
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Property
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ScriptMethod
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ScriptProperty
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ShowExcludeProperty
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ShowProperty
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Skip
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-SkipLast
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-TypeName
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Unique
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Wait
PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value