This is you fighting the “object pipeline”, wishing you could extinguish it and hoping what’s left will be easier.

It’s not going away, fire can’t eat you, and anyway fire lifts space-rockets and you can’t put a satellite in orbit with just strings of text and no rocket boosters.

Is this scenario familiar? You have a file, you want to get its length in bytes (3069) but instead you are getting something like this:

Length ------ 3069

or

@{Length=3069}

It’s messing everything up and you don’t understand why?

Stick with this for juuuust a couple of moments, the answer is two simple realisations away:

What you see is *not* what you get. It used to be, in the cmd prompt, with batch files If you saw “3069” on the screen, that’s what you got – some text, it couldn’t be anything else. With PowerShell, the things in the computer can be more complex than that – but there’s no easy way to show them on screen, in writing, for us people to read.

PowerShell tries to show us, that’s the output you’re getting, but it’s like describing a picture in words – lots of important stuff is missed out and you can’t take the summary and treat it like the original picture.

That @{} Length —- stuff is telling you “you don’t have a number, or some text, you have an object“.

What’s an ~ object ~ ?

2. It’s a collection of several things carried along together, with labels saying what they are. More or less, that’s all it is. And that’s why you can’t show it just as a simple text description, it doesn’t fit.

This purple thing is a spice rack (from somewhere which doesn’t speak English – pictures from pexels.com, because their pictures are freely licensed, and for $0 I can put up with it saying ‘Salz’ instead of ‘Salt’).

See how it has separate and neatly labelled containers for spices so they can’t mix? So you can find the one you need? I highlighted them in beige for you. Isn’t that brilliant – carry your file name, path, creation date, and length in bytes along all together but separate?

That’s our model for an object.

You wanted the salt to put in your dinner.

What you did was write one of these in your code:

a) Get-SpiceRack | Select Salt

b) Get-SpiceRack | Select-Object Salt

These give you:



Salt

——

3069 (grains? who knows, don’t push the analogy too far)



c) “$(Get-SpiceRack | Select Salt)” This gives you:

@{Salt=3069}

And instead of getting salt for your dinner, you got a container with salt in it, with a label saying ‘salt’, and put that in your dinner. And now your dinner is throwing exceptions at you, and it’s just salt, and why is Microsoft making seasoning difficult, what was wrong with MMC and the Salt snap-in?

That’s what “Select-Object” does – it makes you a new custom object tailored to your needs. Just the containers you specify, and their labels, and their contents.

Even if you only specify one thing, you get an object with one container, and the label and contents of that container.

To get “just the salt”, you need to get the content of the container, and you do that in one of these ways:

Get-SpiceRack | Select -Expand Salt

Get-SpiceRack | Select-Object -ExpandProperty Salt

( Get-SpiceRack ) . Salt

They all have the same effect and output just 3069. That’s what salt is now, it’s a number of file length in bytes. My blogpost is all mixed up – if only I had a way of keeping things separate but also moving them along together?

Example:

S D:\> Get-ChildItem .\Untitled1.ps1 | select Length

Length

——

3069

PS D:\> Get-ChildItem .\Untitled1.ps1 | select -expand Length

3069

The weird formatting on the first one screams “Object with Length property”, and the second one is “just a number”.



3069 PS D:\> $fileDetails = Get-ChildItem .\Untitled1.ps1PS D:\> $fileDetails.Length3069 PS D:\> $fileDetails | Select-Object Length Length

——

3069

Here too, store the details in a variable, and either get the content, or a custom object with a length property.

Conclusion: This is where you put your conclusion after writing yet another object tutorial. Feel free to wonder why you reinvented the wheel, didn’t Google for an existing tutorial to link people to, and encourage people to visit your upcoming “stop using |ft because it is a symptom of exactly the same problem of “what you see is a text representation of what you actually have, missing the details”” post.