Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Input, filter and output-PowerShell 3 minutes (8)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

There are many ways for PowerShell to input data, including entering characters directly, importing data, capturing interface input, etc.

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

This method is very common and is very convenient for queries and operations with less requirement information.

In addition, there is Read-Host for interactive input:

Because it is interactive input, it is mostly used for scripts that must be intervened by the user.

If a large amount of data input is involved, Get-Content is required.

First prepare a txt. Each row is the data that needs to be entered.

All the data in the document can be obtained through Get-Content.

Then it can be operated through the pipeline.

The function of the Import-Csv command is similar to that of Get-Content, except that Import-Csv is imported through a Csv file, and each line of import is an object

Here, you should note that the first line is the property name of the object. Here I named it Name, and you can also define it as other names.

Import ~ ~

OK~~

This is the end of the basic input, of course, there are many ways to input data, not one by one here, you can use Get-Command to find more import methods.

Next, let's talk about filtering: by filtering, we can display the information we need more accurately, that is, using the Where-Object command.

Of course, there are two ways to compare. The first is the format of the comparison sentence, and the second is the format of the script block. The function of the two commands is the same. Just choose the one you are used to.

The above example is a simple judgment of whether it is equal to, and there are other conditional judgments.

As there are so many conditions, it is really not good to write them all, you can go to https://technet.microsoft.com/zh-CN/library/dd315321.aspx to see more comparison operators.

Finally, let's talk about the output.

Commonly used outputs such as Write-Host can output the results to the PowerShell interface

Of course, not all requirements have to be printed to the screen, sometimes they need to be output to files, and sometimes individual attributes should be selected.

Here is a brief list:

In addition, there are

Usually, you can select the content you want to output first according to your needs, and select the attributes by formatting Format-List Format-Table or Select-Object

Then output to another location, such as a file

Dangdang, finish

Finally, I introduce an interesting command, Out-GridView.

All right, that's all for today's three minutes. Everybody, hurry up and practice.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report