I've been stuck on this for a while now... Basically i have a SQL database that my PS Script fetches using Invoke-Sqlcmd:
$nocToolsDatabase = Invoke-Sqlcmd -query "Select * from tb_noctools" -ServerInstance $sqlServer -Database $database -user $user -pass $password
And I am cross referencing the fields in the Table with values from an API in a Foreach loop with IF statements:
foreach ($shItem in $shIncidentsWithNocToolsAndInc) {
if ($nocToolsDatabase.INC -eq $shItem.INC) {
"YES IT DOES MATCH"
if ($shItem.incident_status[0] -notin $nocToolsDatabase.sh_status) {
"YAY"
} else {
"ERROR"
}
} else {
write-host "NO IT DOESNT" -ForegroundColor Red
}
}
The first IF statement works fine, but the second one compares $shItem.incident_status[0] which has one value to $nocToolsDatabase.sh_status which for some reason compares all results in that table under the sh_status column instead of the individual row based on the previous IF statement filter.
The API values are:
| INC | incident_status[0] |
|-----------|--------------------|
| INC1234 | resolved |
| INC123456 | resolved |
Database table:
| INC | sh_status |
|-----------|---------------|
| INC1234 | resolved |
| INC123456 | investigating |
So basically the second IF statement should return "YAY" for INC123456 because the API value is resolved, however on the database it is set as investigating.
Any ideas?
TIA