November 2018
Intermediate to advanced
566 pages
17h 15m
English
The flow is simple. All we have to do is replace the contains operator with like or match:
$Names = Get-Content ./ch09/02-names.txt$Names = $Names -match 'son$'# or $Names = $Names -like '*son'$NewNames = @()
foreach ($Name in $Names) {
$Name = $Name -split ' '
$NewName = $Name[1], $Name[0] -join ', '
$NewNames += $NewName
}
$NewNames
Alternatively, you could swap the second and the third steps and use a slightly different approach:
$Names = Get-Content ./ch09/02-names.txt $NewNames = @() foreach ($Name in $Names) { $Name = $Name -split ' ' $NewName ...Read now
Unlock full access