I need help. I have to object arrays $mySQL and $tassSQL which i need to loop through and compare the column named folder code 1 and if this column data is not listed in $mySQL then add the info into a hash table.
So far my code looks like the following: However, i seem to still have it populating with all data.
$mySQL = @(
[pscustomobject]@{
'Parent ID' = '234';
'Folder Name' = 'Senior Visual Art 31 2023';
'Folder Colour' = '#45640b3'
'Folder Picture' = $null
'Folder Code 1' = '-VARSR-31'
'Folder Code 2' = $null
'Folder Code 3' = $null
'YearLevel' = '12'
}
[pscustomobject]@{
'Parent ID' = '264';
'Folder Name' = '10 Manual Art 1 2022';
'Folder Colour' = '#45640b3'
'Folder Picture' = $null
'Folder Code 1' = '-MAAR10122'
'Folder Code 2' = $null
'Folder Code 3' = $null
'YearLevel' = '10'
}
)
$tassSQL = @(
[pscustomobject]@{
'Parent ID' = '234';
'Folder Name' = 'Senior Visual Art 31 2023';
'Folder Colour' = '#45640b3'
'Folder Picture' = $null
'Folder Code 1' = '-VARSR-31'
'Folder Code 2' = $null
'Folder Code 3' = $null
'YearLevel' = '12'
}
)
$classes = @()
ForEach ($classCode In $tassSQL)
{
$parent = $classCode.'Parent ID'
$Name = $classCode.'Folder Name'
$Colour = $classCode."Folder Colour"
$code1 = $classCode.'Folder Code 1'
$grade = $classCode.'YearLevel'
If ($MySQL.'Folder Code 1' -notcontains $code1)
{
$classes += New-Object PSObject -Property @{
'Parent ID' = $parent
'Folder Name' = $Name
'Folder Colour' = $Colour
'Folder Picture' = $null
'Folder Code 1' = $code1
'Folder Code 2' = $null
'Folder Code 3' = $null
'YearLevel' = $grade
}
}
}