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"<br>
        Selects the properties Name and Length, renaming Length to Size in the process.<br>
Example 2: Converting type
        Import-Csv .\file.csv | Select-DbaObject Name, "Length as Size to DbaSize"<br>
        Selects the properties Name and Length, renaming Length to Size and converting it to [DbaSize] (a userfriendly representation of<br>
        size numbers contained in the dbatools module)<br>
Example 3: Selecting from another object 1
        $obj = [PSCustomObject]@{ Name = "Foo" }<br>
        Get-ChildItem | Select-DbaObject FullName, Length, "Name from obj"<br>
        Selects the properties FullName and Length from the input and the Name property from the object stored in $obj<br>
Example 4: Selecting from another object 2
        $list = @()<br>
        $list += [PSCustomObject]@{ Type = "Foo"; ID = 1 }<br>
        $list += [PSCustomObject]@{ Type = "Bar"; ID = 2 }<br>
        $obj | Select-DbaObject Name, "ID from list WHERE Type = Name"<br>
        This allows you to LEFT JOIN contents of another variable. Note that it can only do simple property-matching at this point.<br>
        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<br>
        Type property of equal value as Name on the input.<br>
Example 5: Naming and styling
        Get-ChildItem | Select-DbaObject Name, Length, FullName, Used, LastWriteTime, Mode -TypeName MyType -ShowExcludeProperty Mode,<br>
        Used<br>
        Lists all items in the current path, selects the properties specified (whether they exist or not) , then ...<br>
        - Sets the name to "MyType"<br>
        - Hides the properties "Mode" and "Used" from the default display set, causing them to be hidden from default view<br>

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