Power shell Study Notes (4) object Pipeline

Source: Internet
Author: User

Object pipeline is a convenient feature of PS. One of the main advantages of using an object is that it enables the use of pipeline transmission commands (that is, it is much easier to pass the output of a command as input to another command. Communication usually requires string operations to convert the output from one format to another, and delete the title and column title. Of course, my favorite is XXXX | get-member. When I don't know how to use it, this queue (get-member) can list all the attributes and methods for you, I guess it.

Windows powershell provides a new Interaction Model Based on objects instead of text. The cmdlet of the recipient can directly act on its attributes and methods without conversion or operation. You can reference the attributes and methods of an object by name, rather than calculating the position of data in the output.

The following are examples:

Example 1: The ipconfig command obtains IPaddress information.

Is the basic usage of ipconfig.

What if I don't want so much information, but only the local IP address? At this time, you can use findstr for processing. To solve this problem, first obtain all the information shown above, and then findstr the information in each line. If "Address" is included, it is what I want. The statement is as follows:

Ipconfig | findstr "Address"

Get the MAC address?

Finally, I will introduce you to my favorite usage XXXX | get-member.

When you get an object, but you don't know which methods are available for the object, you can guess whether it can obtain any information or implement certain functions, XXXX | get-member is the most useful.

For example, get-service can obtain information about a service, but I don't know how to start this service. Object-oriented thinking ~ Let's talk about the object! A lot of people will do this. But what if you get the service object? What methods are provided for service objects? Get-member! As follows:

1. Get MSDTC Service Information and output all attribute information through the format-list method. We can see that the status is running.

2. We want to disable it. But I don't know how to handle it. Let's take a look at what methods he provided.

As you can see, get-member lists all the members. OK. We found that there is a method called STOP. I think most people can guess what to do.

So let me test it.

First, we get the service object of MSDTC, and then call the stop method (method, of course, parentheses ).

Then a new status information is output, and the status changes to stopped first. We successfully disabled the service. A very useful method.

Object pipelines also have many usage and many common methods, but wait for them to be used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.