Input, filter and output--powershell three min (eight)

Source: Internet
Author: User

Today's three minutes to give you a summary of PowerShell daily data input filtering and output processing


PowerShell input data in many ways, including direct input characters, import data, capture interface input, etc.

For less information, you can manually enter it directly in the PowerShell interface:

This is a common approach and is very convenient for queries and operations that require less information

In addition, there are read-host for interactive input:

Because it is interactive input, it is used for scripts that must be user-intervened

If the input of a large amount of data is involved, you need to use Get-content

Prepare a txt first, and each line is the data that needs to be entered

All data within a document can be obtained through get-content

Then you can use the pipe to

The Import-csv command and the Get-content function are similar, except that Import-csv is imported through a CSV file, and each imported line is an object

Here you should note that the first line is the property name of the object, where I name it, and you can define it as a different name.

Import a bit ~ ~ ~

ok~~

The basic input is introduced to this, of course, there are many ways to input data, here are not listed, we can go through the Get-command to find more ways to import



Next, filter: Through the filter, you can more accurately display the information we need, that is, with the Where-object command

Of course, there are two ways to compare, the first is the comparison statement format, the second is the script block format, the role of two commands is the same, choose a habit of their own good


The above example is a simple judgment is equal to, besides there are other conditions to judge

Because of the many conditions, really bad are written out, you can go to https://technet.microsoft.com/zh-CN/library/dd315321.aspx see more comparison operators


Finally, say the output ~ ~ ~

Common output such as write-host can output the results to the PowerShell interface

Of course not all the requirements are printed to the screen, sometimes need to output to a file, sometimes to select the individual properties

Here is a brief list of the following:

Besides, there are


Typically, you can select what you want to output by selecting the property by formatting Format-list format-table or Select-object.

And then output it to another location, such as a file

When when, finish


Finally, an interesting command is introduced Out-gridview


All right, I'll be here in three minutes today, guys.



Input, filter and output--powershell three min (eight)

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.