simple string extraction from enrollments

I wanted to get a list of students in a BB course.  I have access to the enrollment files (on a UNC share).  I get content from the file, split the string to get the name, put the name into an array IFF it is not already in there.

$aa = gc W:\FallStudents.txt|select-string -pattern "GDD" -casesensitive
$GIDD = @()
foreach ($a in $aa){
$array = $a.tostring().split("|")
if ($GIDD -notcontains $array[1] ){
$GIDD += $array[1]
}
}

the string (the pipe separated course, studentname and role) must contain the course-id “GDD” and also a number and semester, et al.  It turns out not to work without the case-senstive switch because of strings in student names.  AND it appears to find either GDD or GD in the names. $GIDD.count is the count in the array.

What if i want to do either GDD or IDD?  Doing -or logic doesn’t work OOTB, so i just ran the get-content\select string twice.  I initialize $GDD twice, add all the GDD student, then look at IDD and ask if they are already in the array (from being in a GDD course).  If not already in, add them.  Finally, take the array, sort it and put it back into the same array.

$GIDD = @()
$aa = gc W:\2013FallStudents.txt|select-string -pattern "GDD" -casesensitive
foreach ($a in $aa){
$array = $a.tostring().split("|")
if ($GIDD -notcontains $array[1] ){
$GIDD += $array[1]
}
}
$bb = gc W:\2013FallStudents.txt|select-string -pattern "IDD" -casesensitive
foreach ($b in $bb){
$array = $b.tostring().split("|")
if ($GIDD -notcontains $array[1] ){
$GIDD += $array[1]
}
}
$GIDD = $GIDD|sort-object

 

 

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.