Hi Matt,
You have given me the last piece of the puzzle I needed to make my Script usable and I thank you and everyone very much as this has been a very good learning curve on what powershell is capable. My initial goal at the start of this project was to create a script that would ask for 3 things Oldstudents.xls, CurrentStudent.csv and School, it would then sort them and produce 3 files on the results.
1.New Students
2.Old Students
3.Current Students
Which all 3 files where uploaded to the service that needed the details updated they only accepted the file in a specific format which is why the final piece of the puzzle looks as it is. I used your initial bases for nested loop and modified it to produce the needed outcome as your format did not produce the desired file format compared to what I needed(this is probably due to me needing to get a better understanding on how array and hash files can be formatted, I will need more work on that later)
This is what it ended up as in the working script
###############################################################################
Updates Current Students ID DOB Tag and Year
###############################################################################
$CurrentStu = @()
ForEach ($lineCurr in $SasFile)
{
If ($AcerFile | Where-Object {$_.‘Unique ID’ -eq $lineCurr.‘Unique ID’})
{
$CurrentStu += $lineCurr
}
}
$New1 = “Student ID,Family name,Given name,Middle names,Username,Passwords,Date of birth,Gender,Tags,Unique ID,Year level,School Year”
$Curr = @()
$Curr += $New1
ForEach ($Obj in $AcerFile){
ForEach ($line2 in $CurrentStu)
{
If ($Line2.gender -eq “F”)
{
$StudentID = $Obj.‘Student ID’
$Fname1 = $Line2.‘Family Name’
$Gname1 = $Line2.‘Given Name’
$Mname1 = ‘’
$Username1 = $Line2.Username
$Password1 = $Line2.Password
$Birth1 = $Line2.DOB
$BirthY1 = $Birth1.Substring(0,4)
$BirthM1 = $Birth1.Substring(4,2)
$BirthD1 = $Birth1.SubString(6,2)
$BirthFixed1 = $BirthD1 + “-” + $BirthM1 +“-” + $BirthY1
$Gender1 = “Female”
$Tags1 = $Line2.Tags
$ID1 = $Line2.‘Unique ID’
$YearLevel1 = ‘Year’ + " " + $Line2.‘Year Level’
$Year1 = ‘2016’
$CurrentStudents = $StudentID + "," + $Fname1 + "," + $Gname1 + "," + $Mname1 + "," + $Username1 + "," + $Password1 + "," + $BirthFixed1 + "," +$Gender1 + "," + $Tags1 + "," + $ID1 + "," + $YearLevel1 + "," + $Year1
}
Else
{
$StudentID = $Obj.'Student ID'
$Fname1 = $Line2.'Family Name'
$Gname1 = $Line2.'Given Name'
$Mname1 = ''
$Username1 = $Line2.Username
$Password1 = $Line2.Password
$Birth1 = $Line2.DOB
$BirthY1 = $Birth1.Substring(0,4)
$BirthM1 = $Birth1.Substring(4,2)
$BirthD1 = $Birth1.SubString(6,2)
$BirthFixed1 = $BirthD1 + "-" + $BirthM1 +"-" + $BirthY1
$Gender1 = "Male"
$Tags1 = $Line2.Tags
$ID1 = $Line2.'Unique ID'
$YearLevel1 = 'Year' + " " + $Line2.'Year Level'
$Year1 = '2016'
$CurrentStudents = $StudentID + "," + $Fname1 + "," + $Gname1 + "," + $Mname1 + "," + $Username1 + "," + $Password1 + "," + $BirthFixed1 + "," +$Gender1 + "," + $Tags1 + "," + $ID1 + "," + $YearLevel1 + "," + $Year1
}
}
$Curr += $CurrentStudents
}
$filename1 = “CurrentStu”
$Curr | out-file $FileName1 -Append
$Current = Import-Csv .\CurrentStu
$Current | Export-Csv .\CurrentStudents.csv -NoTypeInformation
Thanks again to everyone who help contribute(even if I did not exactly use your script or method) it has helped me to create a script which will be useful.