I am running a very simple TSQL code in powershell. But the output only shows number of affected rows but not the actual results. Code is as follows:
function test([string] $Hostname )
{
try
{
$con="server=$Hostname;database=master;Integrated security=sspi"
$da=New-Object System.Data.SqlClient.SqlDataAdapter ("
select * from sysdatabases
",$con)
$dt=New-Object System.Data.DataTable
$da.fill($dt)|Out-Null
$da.fill($dt) | Format-table -AutoSize
}
catch [Exception]
{
## Do something with the exception
write-host "Could not run test function for "+$Hostname
}
}
foreach ($Hostname in Get-Content $ServerList)
{
test($Hostname)
}
Any help please?
Thanks in advance