I am trying to merge data from two different sources and export that into a CSV or txt file by making use of a PSObject.
$qry = New-Object System.Data.SqlClient.SqlCommand("SELECT Name, IsCompliant,LatestEntry,ComputerManufacturerName,ComputerModelName,OperatingSystemName,MachinesUsersNames,ErrorInfoName FROM ComplianceCore.MachinesComplianceView WHERE isCompliant='false'", $conn)
$adapter = New-Object System.Data.SqlClient.SqlDataAdapter $qry
$dataset = New-Object System.Data.DataSet
$adapter.Fill($dataset) | Out-Null
$conn.Close
$resultObject = New-Object -TypeName psobject
foreach ($data in $dataset){
$resultObject | Add-Member -MemberType NoteProperty -Name Name -Value $dataset.Tables.Name
$resultObject | Add-Member -MemberType NoteProperty -Name ComputerManufacturer -Value $dataset.Tables.ComputerManufacturerName
$resultObject | Add-Member -MemberType NoteProperty -Name OperatingSystemName -Value $dataset.Tables.OperatingSystemName
$resultObject | Add-Member -MemberType NoteProperty -Name Tenant -Value (get-adcomputer -filter * -property CN | Where-Object { $_.Name -in $dataset.tables.name } | select-object CN)
}
$resultObject | Out-file -filePath "C:\BAC\WSUSScripts\MBAM Compliance\MBAMErrors.txt"
Also I'd like to run the query against the AD to retrieve some tenant information but no success.
The result is either when i export to csv a system.object or a value something like this {Microsoft Corporation, Dell Inc., Dell Inc., Dell Inc....} when i want everything to be formatted underneath each other in a table.