How to expand [pscustomobject] properties

I am trying to figure out how to expand my custom objects that I created using [pscustomobject].

The output looks like this:

RenamedFrom RenamedTo

PS Test 1… PS Test 1…

How do I get the output to appear as:

RenamedFrom RenamedTo

PS Test 1 PS Testing 1
PS Test 2 PS Testing 2
PS Test 3 PS Testing 3

Thanks everyone

Pipe it to Format-Table -AutoSize. :slight_smile: (In the latest versions of PowerShell 5.0, PowerShell does this automatically for the first few objects in the pipeline.)

Is the ; you show in your output part of the data?

Here is a portion of my code:

[pscustomobject] @{
    'RenamedFrom' = $OldName ;
     'RenamedTo' = $NewName

How would I pipe this to Format-Table?

Richard, I thought the semicolon is supposed to be part of the syntax to delimit the next the object?

You’re not doing anything with the data you collected above. In this sample, I read in a CSV file with the column headings of OldName and NewName.

$results = Import-Csv -Path C:\Ephemeral\filenames.csv | foreach {
        RenamedFrom = $_.OldName
        RenamedTo = $_.NewName
# sample outputs
$results | Format-Table -AutoSize
$results | Out-GridView
$results | Export-Csv -Path .\foo.csv -NoTypeInformation -Encoding ASCII
$results | Out-File -FilePath .\foo.txt -Encoding ASCII

I am so absent minded sometimes. I forgot that I had used an out-string earlier in my code and saved the data to a variable using -outvariable so I can re-use that, as part of the final output later which is what the code I initial posted was. This must be why it cannot do what I want, because it is a string and not objects now.

Is there a way to save actual objects in a variable without piping to Out-String -OutVariable?

It’s a little unclear what you’re trying to accomplish. Are you trying to save the contents of an object to a file so it can be used later in another script or function? If that the case I would use ExportClixml.

$results | Export-Clixml -Path .\foo.xml -Encoding ASCII

Well kind of, but I like to avoid using files if I can use variables instead, but I don’t think it is possible in this case.

I think I will just go with your idea, Bob.