Hi guys,
I’m struggling with the output from Invoke-Sqlcmd. If I run the query in MS SQL Management Studio, I get two rows as result from a table containing computernames.
If I put the query in $SQLselect and run the following code in PowerShell, the $SQLSelectResult variable will only contain one object with TypeName: System.Data.DataRow.
$SQLSelectResult = Invoke-Sqlcmd -Query $SQLselect -ServerInstance $SQLServer -Database $Database
I have also tried things like
Invoke-Sqlcmd -Query $SQLselect -ServerInstance $SQLServer -Database $Database | foreach { Write-Output $_.COMPUTERNAME }
with only one computername as result.
I just can’t figure out how I can get the same result in SQL Management Studio and PowerShell. I think PowerShell always gives me the last row of the query.
Any suggestions how I can solve this?