The following code I have is fetching data from SQL however the -ne operator is not working correctly when I have more than one object in $teamConfig.
The following Code outputs the following:
$teamConfig = @(
[pscustomobject]@{
TeamName = 'Team1'
TeamEmail = '[email protected]'
}
[pscustomobject]@{
TeamName = 'Team3'
TeamEmail = '[email protected]'
}
)
$query = "select * from INCAutomation"
$results = Invoke-Sqlcmd -query $query -ServerInstance 'localhost' -Database 'AyushTest'
foreach ($item in $teamConfig) {
$teamsExcluded = $results | Where-Object TeamName -ne $item.TeamName | Select TeamName
}
$teamsExcluded
Result:
TeamName
--------
Team1
Team1
Team1
Team1
Team2
Team2
Team2
After removing Team3 from the $teamConfig (example) I get the following desired output:
$teamConfig = @(
[pscustomobject]@{
TeamName = 'Team1'
TeamEmail = '[email protected]'
}
)
$query = "select * from INCAutomation"
$results = Invoke-Sqlcmd -query $query -ServerInstance 'localhost' -Database 'AyushTest'
foreach ($item in $teamConfig) {
$teamsExcluded = $results | Where-Object TeamName -ne $item.TeamName | Select TeamName
}
$teamsExcluded
Result:
TeamName
--------
Team2
Team2
Team2
I've been stuck on this one for a little while, thanks in advance!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…