Terms of Use For FixedByVonnie

By proceeding to access fixedByVonnie.com, you expressly acknowledge, and agree to, all of the following:

fixedByVonnie.com is a personal website and blog owned by Security Plus Pro LLC, which is being presented for informational purposes only. The views on this website are solely those of the website owner (and not those of any employer or of any professional associations affiliated with the website owner).  Any views expressed in this website and any information presented on this website, or in any of its blog entries, should not be relied on for any purpose whatsoever other than as the personal opinions of the website owner.  The website owner expressly disclaims any and all liability for any information presented on this site.  The owner of this website and its blog posts shall not be held liable, and shall be held harmless, for any errors or omissions in any information or representations contained in this website, or in any of its blog entries.  The website owner also expressly disclaims any liability for the current or future availability of any such information. The website owner makes no representations as to the accuracy or completeness of any information on this website or which may be found by following any link on this website. The website owner shall not be held liable for any losses, injuries, damages, claims, or causes of action, from the display or use of any information on this website or in any of its blog entries. If you use the information on this website, or on any of its blog entries, you do so solely at your own risk.

Say what’s up to PowerShell 5 (Part 16/27) - fixedByVonnie

Say what’s up to PowerShell 5 (Part 16/27)

Today I want to talk about looking at only what you want.

For example, when you type Get-Service you see three columns (three properties) displayed by default:

  • Status
  • Name
  • DisplayName

But we know a service has more properties than that!  So how can we change what columns PowerShell displays here?

That’s the focus of this post.

Whenever you want to know everything there is to know about an object pipe it to Get-Member (GM).

gsv | gm

gsv | gm

Okay, so let’s just select the Service Name, Status and Machine Name.  That way we can see which services belong to which computers.

You see… when we simply type Get-Service without any qualifications it returns Status, Name and DisplayName.

These are the properties. Columns are properties and rows are objects.  Each row is a unique Service object.

So if we want to change the view so Service Name, Status and Machine Name show up we need to explicitly select which properties of these objects we want displayed.

gsv

We do this by piping Get-Service to Select-Object and using the -Property parameter with our list of column headers:

gsv | select -property name, status, machinename

Select is just a partial parameter for Select-Object (sort of like an alias) so don’t let that trip you up.

Okay, so let’s see if the DHCP service is running on the two computers in my lab: dc16alx1 and ws11alx1.

gsv dhcp -computername dc16alx1, ws11alx1 | select -property name, status, machinename

gsv with select-object

Nice, and now I can ship this data as a CSV, as an XML file or even as a HTML page.  Or if I want I can just pipe it as a text file.

For example, here’s how we could export all that jazz to a CSV file.

gsv dhcp -computername dc16alx1, ws11alx1 | select -property name, status, machinename | Export-Csv -Path 'c:\dhcp.csv'

In the next post we’ll look into formatting the output.

About

Connect with Vonnie on Twitter

Posted in Windows, Windows 10 Tagged with: