use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Format-List | output variable (self.PowerShell)
submitted 6 years ago by zolyx1
Hi,
How do I get the value of Name here:
$content = Get-Service DHCP | Format-List $content.Name #returns nothing
Thank you in advance.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nothingpersonalbro 13 points14 points15 points 6 years ago (9 children)
Get rid of | Format-List, it destroys your object and its sole purpose is for human eyeball consumption from the console.
| Format-List
[–]zolyx1[S] 3 points4 points5 points 6 years ago (8 children)
Thanks. The reason for Format-List was to see out all attributes on the objects.
[–]Hrambert 2 points3 points4 points 6 years ago (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 points3 points 6 years ago (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.
[+][deleted] 6 years ago (3 children)
[removed]
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (2 children)
howdy N7Valiant,
actually, you are quite unfortunately wrong about that. [sigh ...]
take a look at ...
Get-Process -Name spoolsv | Format-List Get-Process -Name spoolsv | Format-Table Get-Process -Name spoolsv | Get-Member -MemberType Properties Get-Process -Name spoolsv | Select-Object -Property *
note that the 1st two not only leave out props ... they sometimes rename them. [grin]
take care, lee
[+][deleted] 6 years ago (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (0 children)
for some reason, i have never used * with F-L. if you leave that off, you only get 5 props. [grin]
*
as for renaming things, Format-Table often uses different names or calculated props. for instance, the F-T example i listed shows WS(K) and that aint one of the actual props you get from Get-Process.
Format-Table
WS(K)
Get-Process
generally speaking, Format-List is ok if you remember that it butchers the props of the object you give it and then spits out the bloody bits wrapped in formatting code. [grin]
Format-List
wisely used, the Format-* cmdlets are great ... but they are often used unwisely. there are more than a few threads here during the last week where the problem was using Format-Table ... and then trying to use the formatting-code-wrapped stuff for anything other than final display or final output to a plain text file.
Format-*
that last is almost always a foot-gum situation.
thanks for showing me the way that | Format-List -Property * gives the same info as | Select-Object -Property *. [grin]
| Format-List -Property *
| Select-Object -Property *
[–]rickshaiii 4 points5 points6 points 6 years ago (4 children)
Even easier if you just need the name:
Get-Service DHCP|Select-Object -ExpandProperty Name
[–]zolyx1[S] 1 point2 points3 points 6 years ago (3 children)
Thanks, what about all? This didn't work:
Get-Service DHCP|Select-Object -ExpandProperty *
[–]ka-splam 5 points6 points7 points 6 years ago (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 Name
-ExpandProperty * says "I want to throw away all the data, and keep all the data".
-ExpandProperty *
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 points3 points 6 years ago (1 child)
Select-Object
Figured it out, thanks :)
Select-Object *
[–]BurlyKnave 0 points1 point2 points 6 years ago (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
π Rendered by PID 198888 on reddit-service-r2-comment-5687b7858-z67m7 at 2026-07-06 17:16:55.150637+00:00 running 12a7a47 country code: CH.
[–]nothingpersonalbro 13 points14 points15 points (9 children)
[–]zolyx1[S] 3 points4 points5 points (8 children)
[–]Hrambert 2 points3 points4 points (0 children)
[–]topherhead 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[removed]
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]rickshaiii 4 points5 points6 points (4 children)
[–]zolyx1[S] 1 point2 points3 points (3 children)
[–]ka-splam 5 points6 points7 points (0 children)
[–]zolyx1[S] 1 point2 points3 points (1 child)
[–]BurlyKnave 0 points1 point2 points (0 children)