How to use Select-Object property to expand all the fields in the power shell command

powershell expand nested properties
powershell select-object
powershell expandproperty
powershell select-object expression
powershell select-object property vs expandproperty
powershell select multiple properties
powershell show all properties
powershell object property in brackets
Get-ChildItem -Path E:\Server_Data\data\2015 -Recurse –File -include "*.txt","*.csv" | Where-Object {$_.Name -like "*transaction*"} | Select-Object -ExpandProperty FullName,LastWriteTime

I'm trying to list all files in a folder using Get-ChildItem and Select-Object property. When I try to use FullName variable to list the fully qualified file name, the file name is getting truncated. Tried to use -ExpandProperty to get fully qualified file name. It works for one field but if I try to list both FullName and LastWriteTime, it's not working.

The output from the power shell command will be used in MS SQL Server to load the file names into a specific table.

Please suggest proper syntax for my purpose. Appreciate your help!


Depending on your use case and input, one way to accomplish this is by having two Select-Object cmdlets in your pipeline, one to define an array of properties, and one to expand them:

PS C:\> $Name,$DisplayName,$Status = Get-Service 
  | Select-Object -First 1 -Property @{
    Name = "MyProperties"
    Expression = { $_.Name,$_.DisplayName,$_.DisplayName }
  } | Select-Object -ExpandProperty MyProperties

Select-Object, To select object properties, use the Property parameter. Beginning in Windows PowerShell 3.0, Select-Object includes an optimization feature When you include a Select-Object command with the First or Index that include the Sort-​Object cmdlet because Sort-Object processes all objects and then returns a collection. Syntax. PowerShell. Select-Object [-InputObject <PSObject>] [ [-Property] <Object []>] [-ExcludeProperty <String []>] [-ExpandProperty <String>] [-Unique] [-Last <Int32>] [-First <Int32>] [-Skip <Int32>] [-Wait] [<CommonParameters>] PowerShell.


If you are only going to do this to display on the console, then you can look at using Format-Table with the -Wrap parameter to display all of the text on the console without truncating the output.

Get-ChildItem -Path E:\Server_Data\data\2015 -Recurse –File -include "*.txt","*.csv" |Where-Object {
    $_.Name -like "*transaction*"
} | Format-Table FullName,LastWriteTime -Wrap

If you are planning on doing anything else with our output, then you will need to avoid the use of Format-* cmdlets as they add custom formatting to the object and render it effectively useless in the pipeline.

Get All PowerShell Object Properties, How do I get all the properties of an object in PowerShell? Use -Property * when you want to see maximum information: Get-Process | Select-Object-Property * Use -Property a,b,c to select more than one column: Get-Process | Select-Object-Property Name, Description, Company. Use -ExpandProperty Column to select exactly one column: Get-Process | Select-Object-ExpandProperty Name


Get-ChildItem -Path E:\Server_Data\main.sweetbeam.net\data\2015 -Recurse –File -include "*.txt","*.csv" | Where-Object {$_.Name -like "*transaction*"} | Select-Object @{Name="test";Expression={$_.FullName + "`t" + $_.LastWriteTime}} | Select-Object -ExpandProperty test

Merged the two fields and used the derived field for my purpose.

What are PowerShell Commands? Code Examples, Tutorials & More, How do I display output in a table format in PowerShell? You can use the Select-Object cmdlet to create new, custom PowerShell objects that contain properties selected from the objects you use to create them. Type the following command to create a new object that includes only the Name and FreeSpace properties of the Win32_LogicalDisk WMI class:


Using Format Commands to Change Output View, The names of all the cmdlets begin with the verb Format . They let you select which properties you want to show. Each object type in PowerShell has default properties that are used when you don't If the Format-Table command can't display all the properties, it removes some columns from the display. Calculated properties or 'building objects' actually accomplishes the same. Both give you structure objects that can be exported to csv/xml/json whatever you please. The syntax is slightly different when you use the New-Object cmdlet or the [pscustomobject] accelerator but essentially you're doing the same with Select-Object.


Hope I'm not late for the game. This one example works for me (Get-Service, more than 1 properties having embedded 'collections' of data)

Get-Service |
Select-Object
Name,
Status, 

... and then in the next lines in your script, the next object(s) that you want expanded should be like this @{Name="CustomCol01";Expression={$_.ServicesDependedOn} },

@{Name="CustomCol02";Expression={$_.DependentService} }

In the example, the 2 offending objects that I need expanded are ServicesDependedOn and DependentService

So yeah by custom making new columns it expands whatever Objects for you

Tested works even when redirecting the final output to a csv like this ... > myfile.csv

How to expand truncated PowerShell Output Properties “Select , What if I want to see all the Usages? You might try trusty format list. Get-​CsPstnUsage | Select-Object usage | fl. Usage : {Internal,  Let’s put this data into a variable so we can look more closely: $info = $p | Select-Object -ExpandProperty StartInfo. Now I can check $info.Length and see a number that matches the number of processes. I can look at $info [0] and see a representation of that object.


Expand multiple embedded objects with, Hey all.. I have a cmdlet where i'm trying to use -expandproperty but im failing miserabley. Calculated properties or 'building objects' actually accomplishes the same. PS C:\powershell> get-nanfsexport | Select -first 1 | select pathname Sorry for having to have you execute so many commands, I do not have these  That must be all of the properties then, right? How can we tell for sure? Use Get-Member to see an object’s properties and methods. The Get-Member cmdlet is used to definitively show us a PowerShell object’s defined properties and methods. We use it by piping the output from our Get-Service cmdlet into Get-Member.


Tell Me More: Expanding Objects and Properties in PowerShell, PowerShell MVP and IT veteran Jeff Hicks discusses a common problem for beginners and explains how to expand objects and properties in PowerShell. They see the output of a command and try to finagle something from the text they see on the Of course, you now know you could use Select-Object. 1. Depending on your use case and input, one way to accomplish this is by having two Select-Object cmdlets in your pipeline, one to define an array of properties, and one to expand them: PS C:\> $Name,$DisplayName,$Status = Get-Service | Select-Object -First 1 -Property @ { Name = "MyProperties" Expression = { $_.Name,$_.DisplayName,$_.DisplayName } } | Select-Object -ExpandProperty MyProperties.


PowerShell ExpandProperty vs Property, I'm only an occasional PowerShell user, and therefore it's taking some for me that I think isn't well explained elsewhere: using ExpandProperty, ExpandProperty is part of the Select-Object cmdlet, and it's used to expand properties of it's fields, properties, and methods, and they are all in the pipeline.