1<#21.PowerShell Array.Foreach(...) The signature is:3ArrayForeach(expression[, arguments ...])4 The first parameter is typically a scriptblock type or a type symbol (representing a type conversion)5The second parameter can be many, and will be used as a$args elements of an automatic variable, passed to the first argument6 72. PowerShell Array.where (...) The signature is:8 Array Where ({expression}[, mode[, Numbertoreturn])9Mode=>[System.Management.Automation.WhereOperatorSelectionMode], default defaultsTen "You can enter the enumeration name directly, and PowerShell will automatically convert, which is, of course, a general rule." OneNumbertoreturn=>[Int32], the default value of 0, means that all occurrences are returned A all enumeration members of [System.Management.Automation.WhereOperatorSelectionMode] are as follows: - Default - ReturnAll matches the Return all occurrences - First - Stop processing after the first match. - returns the first few occurrences + Last - ReturnThe last matching element + returns the last few occurrences A Skipuntil atSkipuntilThe condition istrue, thenreturnThe rest - ignores all items before the first match and returns all remaining items, with the first match - Split - ReturnAn array of both elements, first index is matched elements, and second index is the remaining elements. - returns an array of only two elements, the first element contains all occurrences, and the second element contains all the mismatches - "At this point the parameter Numbertoreturn can only determine the return amount of the match, and the discarded matches because of Numbertoreturn will be added to the mismatch in the order in which they appear in the original array" in Until - ReturnElementsuntilThe condition istrueThen skip the rest to returns all elements before the first match, without the first occurrence + #> -Write-host 1.1. Get a arithmetic progression the(1..10).ForEach({$args[0] *$_-$args[1]}, 2, 1) *Write-host 1.2. Get all uppercase letters $(65..90).ForEach([char])Panax Notoginseng -Write-host 2.1filter to get an even number within 10 the(1..10). Where ({$_# t-eq0 }) +Write-host 2.2The filter gets an even number within 10, but takes only the first A(1..10). Where ({$_% 2-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::First ) theWrite-host 2.3filter to get an even number within 10, but take only the first three +(1..10). Where ({$_% 2-eq0}, [System.management.automation.whereoperatorselectionmode]::first, 3) -Write-host 2.4The filter gets an even number within 10, but takes only the last $(1..10). Where ({$_% 2-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::Last ) $Write-host 2.5filter to get an even number within 10, but take only the last three -(1..10). Where ({$_% 2-eq0}, [System.management.automation.whereoperatorselectionmode]::last, 3) -Write-host 2.6filter to get all number items before the first number that can be divisible by 3 within 10 the(1..10). Where ({$_% 3-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::Until) -Write-host 2.7filter to get the first 3 digits of all number items before a number within 10 that can be divisible by 3Wuyi(1..10). Where ({$_% 3-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::Until, 3) theWrite-host 2.8The filter gets all the number items after the first number within 10 that can be divisible by 3, and includes the first number that can be divisible by 3 -(1..10). Where ({$_% 3-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::skipuntil) WuWrite-host 2.9The filter gets all the number items after the first number within 10 that can be divisible by 3, and includes the first number that can be divisible by 3, but only the first 3 digits -(1..10). Where ({$_% 3-eq0}, [System.management.automation.whereoperatorselectionmode]::skipuntil, 3) AboutWrite-host 2.10filter to get even and odd items within 10, respectively $(1..10). Where ({$_# t-eq0}, [System.Management.Automation.WhereOperatorSelectionMode]::Split) -Write-host 2.11filter to get the even and odd items within 10, and only the first 3 of the matches, the rest of the numbers are all returned to the unmatched -(1..10). Where ({$_# t-eq0}, [System.management.automation.whereoperatorselectionmode]::split, 3) -Write-host 2.12filter to get the top 3 of even numbers within 10 A(1..10). Where ({$_% 2-eq0}, 'default', 3)
PowerShell Array method foreach () and Where ()