Setting Fields in a File as Variables

by pitccorp01 at 2013-04-11 12:59:28


I have an input file that has two fields without headings separated by whitespace, where the first field contains names and the second field contains numbers. For example,

Anthony 14
Mike 9
John 21
Sally 10
Mary 9
Jenefer 71

How can I write a Powershell script that will loop through the input file and set each line (n) of the first field as $NAME.n and each line (n) of the second field as $NMBR.n, where .n=line count?

by Nobody at 2013-04-11 13:16:44
Try this

$input = ".\testdata.txt"
$data = import-csv -path $input -delimiter " " -header "name","number"