There are a few commands in PowerShell that will help you right off the bat.
Checking the status of a setting or property
Most of the time when I’m using PowerShell it’s because I need to first look something up, then make a change. We don’t normally just start making changes all willy-nilly, so knowing how to see the properties and changes is the first step in determining how you plan to make a change.
Format-List
Let’s say, for instance, you want to know the ID of a service. Your first command will be:
1 2 3 |
get-service |
But that will list all of the properties of all of the services:
If you want to see just one of the properties, such as the display name, then you’d send the get-service through the “pipeline” with a Format-List. You can start with formatting the list using the property, only showing the property you want. In this case it will be “displayname”
1 2 3 |
get service | format-list -property displayname |
This will show only the property “displayname” as shown below:
You can do multiple properties:
1 2 3 |
get-service | format-list -property status, displayname |
Will show you the displayname and that status:
The more properties you have available, the more options you can see and things you can change based on the commandlets.
But what if I don’t know the properties? get-member to the rescue:
get-member will show you everything property an item has you can format the list with. Here’s how it’s used:
1 2 3 |
get-service | get-member |
This shows you all of the available properties:
That doesn’t mean that all of these properties have values in them. For example if you did this:
1 2 3 |
get-service | format-list -property site |
It may return blank.
And don’t forget, you can write these commands faster when you learn the shortened syntax of some of the commands.
For example this:
1 2 3 |
get-service | fl -p displayname |
Will give you the same as it’s lengthier command:
1 2 3 |
get-service | format-list -property displayname |
I hope this helps a little bit. There’s a lot more to finding what you need before acting on it, but it’s a better idea to first find a way to look something up for actually changing something.
Recent Activity