PowerShell is the shell language in Windows. It provides more windows operations, making Windows operations easier and easier, and the Administrator's command line is better managed. PowerShell provides operability with. net FCL.net class library). We can use the powerful. net FCL in PowerShell. PowerShell provides a powerful pipeline model. A pipeline refers to a command output that can be conveniently transmitted to the next command as input using the operator |. PowerShell uses different traditional pipeline models as an object-based pipeline stream, that is, the objects transmitted between commands are not simple texts. Below we will use local file operations to practice common PowerShell pipeline commands:
1: Set traversal ForEach-Object: Can be abbreviated as foreach, or % instead, provides the traversal of the Set passed in by the pipeline, and provides the begin before the operation, the process operation, end the end command. $ _ indicates the current index.
Example: We will use ForEach-Object to calculate the file size of the local file directory:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1I20W4P-0.png "width =" 697 "height =" 145 "/>
2: Select Where-Object as the condition: Can be abbreviated as where or? . Filters MPs queue input sets. Similar to the where condition in SQL, $ _ provides a reference to the current index.
Example: Name and size of an output file larger than KB:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1I20V3N-1.png "width =" 716 "height =" 348 "/>
3: Select-Object: select, which is short for select. The Object selection is similar to the Select statement of SQL, and the new anonymous Object of. net. At the same time, select supports-first and-last to take the first or last few values, which are equivalent to top in SQL. It is useful to combine with Sort-Object in the following example.
Example: select the file name and size output in the directory:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3b707d0 "border =" 0 "alt =" SNAGHTML3b707d0 "src =" http://www.bkjia.com/uploads/allimg/131228/1I20V240-2.png "width =" 709 "height =" 277 "/>
4: Sort sort-Object: Sort. You can specify-descending as the reverse order for sorting collection objects by referring to one or more attributes.
Example: Obtain the top five objects at most:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3bc4128 "border =" 0 "alt =" SNAGHTML3bc4128 "src =" http://www.bkjia.com/uploads/allimg/131228/1I20Wc5-3.png "width =" 716 "height =" 222 "/>
5: The Pipe tree Tee-Object is abbreviated as tee. You can record the Object imported by the pipe model in the file log or assign a value to the variable for saving. -InputObject,-FilePath,-Variable
Example: $ test variable when saving the file object:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3c03d8f "border =" 0 "alt =" SNAGHTML3c03d8f "src =" http://www.bkjia.com/uploads/allimg/131228/1I20W1V-4.png "width =" 722 "height =" 240 "/>
6: Group-Object: group, which is abbreviated as group. The attribute Group is similar to SQL group.
Example: group by file type and sort by the number of files in the group
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3c30688 "border =" 0 "alt =" SNAGHTML3c30688 "src =" http://www.bkjia.com/uploads/allimg/131228/1I20R363-5.png "width =" 718 "height =" 205 "/>
7: Set statistics Measure-Object: Abbreviation: measure, provides statistics on the set, a simple way to get the minimum, maximum, and average attributes.
Example: minimum, maximum, average, and total size of the statistical file:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3c60aad "border =" 0 "alt =" SNAGHTML3c60aad "src =" http://www.bkjia.com/uploads/allimg/131228/1I20S5D-6.png "width =" 726 "height =" 206 "/>
8: Compare-Object: diff, which provides a comparison between two objects or sets. One of them has a single-side streamer, which is equal to & gt; indicating that this Object appears on the right, & lt; = indicates that the difference object exists on the left.
Example: Create a folder 2 to compare different directories:
650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" SNAGHTML3cb035d "border =" 0 "alt =" SNAGHTML3cb035d "src =" http://www.bkjia.com/uploads/allimg/131228/1I20W441-7.png "width =" 726 "height =" 244 "/>
Today, PowerShell is very powerful. Continue to learn.