How it works...
This script block is a simple implementation of array manipulation. The first line of the script imports the names from the input file into the $Names variable.
We initialize a new array, $NewNames, to store the names in the LastName, FirstName format. Get-Content imports the text in the input file in the form of an array, the newline character being the separator of elements. Since $Names is an array, using the foreach loop to perform operations on the elements is possible.
Within the loop, we split the single string into two strings using the split operator. This, of course, converts $Name from a string into an array; the first name is the first element of the array, and the last name is the second. Next we perform a concatenation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access