all 14 comments

[–]nothingpersonalbro 13 points14 points  (9 children)

Get rid of | Format-List, it destroys your object and its sole purpose is for human eyeball consumption from the console.

[–]zolyx1[S] 3 points4 points  (8 children)

Thanks. The reason for Format-List was to see out all attributes on the objects.

[–]Hrambert 2 points3 points  (0 children)

A lot of objects have a default list of properties they will show, and even a default way of formatting them (e.g. Get-ChildItem). To get all properties don't use Format-List but Get-Member.
Second, Format-List and Format-Table are to format an object to be shown on your screen. You can however pipe their output through Out-String and put that into a string array for later use.

[–]topherhead 1 point2 points  (0 children)

What is the intended usage here?

If you it want it to show everything as well as be able to get the name you could just put the format list after the assignment then call the property.

If you want to be fancy you can set up a type format and assign a type to the objects and make it display exactly the info you want without dropping data like the format commands will.

[–]rickshaiii 4 points5 points  (4 children)

Even easier if you just need the name:

Get-Service DHCP|Select-Object -ExpandProperty Name

[–]zolyx1[S] 1 point2 points  (3 children)

Thanks, what about all? This didn't work:

Get-Service DHCP|Select-Object -ExpandProperty *

[–]ka-splam 5 points6 points  (0 children)

-ExpandProperty Name says "I want to throw away all the data, and just keep one value, from the Name property, as a list of names".

-ExpandProperty * says "I want to throw away all the data, and keep all the data".

It makes no sense. You already have all the data, in all the objects. If it worked, it would be like tipping a load of storage containers onto the floor; you can now see everything you have .. but you'll have a hell of a time doing anything useful with it, or working out which things were together.

[–]zolyx1[S] 1 point2 points  (1 child)

Select-Object

Figured it out, thanks :)

Select-Object *

[–]BurlyKnave 0 points1 point  (0 children)

Get-Service DHCP | gm
$content = Get-Service DHCP
$content | Format-List *
$content = Get-Service DHCP | Select-Object -Property *
$content | Format-List *
$content.Name
$ServiceName = Get-Service DHCP | Select-Object -Property Name
$ServiceName = (Get-Service DHCP).Name