I have populated two results which I want to compare. One result comes from a SQL Server query, the other from PowerShell using the dbatools module. The results appear the same, but comparing does not return true. Some sample set up code may explain this better:
-- Sql Server
use tempdb;
create table dbo.Jobs (
JobName varchar(16)
);
insert dbo.Jobs values ('test');
exec msdb.dbo.sp_add_job @job_name = 'test'
## PowerShell
$exp = Invoke-DbaQuery -SqlInstance $env:computername -Database tempdb -Query "select JobName from dbo.Jobs" | Select-Object -Property JobName -First 1
$rec = Find-DbaAgentJob -SqlInstance $env:computername -JobName test | Select-Object -Property JobName -First 1
$exp # one row
$rec # one row, same value, same header
$exp -eq $rec ## False, expected true
$exp.GetType() # PSCustomObject
$rec.GetType() # PSCustomObject
$exp[0] # one row
$rec[0] # one row, same value, same header
$exp[0] -eq $rec[0] # False, expected true
$exp[0].JobName # one row
$rec[0].JobName # one row, same value
$exp[0].JobName -eq $rec[0].JobName # True (Finally!)
$rec | Where-Object { $_.AgentJobName -notin $exp } # returns the value in $rec, should return nothing
$rec | Where-Object { $_.AgentJobName -in $exp } # returns nothing, should return the value in $rec
I am using PowerShell 5.1. I believe the two PowerShell variables should compare as being the same by just passing the variables alone. Ultimately my goal is to use more complex queries, following the example above, I would like to compare multiple jobs and multiple properties without having to iterate all the values. Initially I had arrays of objects and I used Compare-Object, but the results were incorrect and I believe it comes down to this simplified example.
I cannot use dbachecks because I cannot install PowerBI, I need to store the results this way for use by another reporting tool. Any help is appreciated.