I have executed SQLquery using powershell and i would like to store the result in log file.
$SelectQuery = "SELECT [$columnName] FROM [$DatabaseName].[dbo].[$TableName];"
$Qresult= invoke-sqlcmd -query $SelectQuery -ServerInstance $srvInstance
Log-Write "$Qresult"
(Log-write is a function which will add the contents to logfile)
But logfile shows as “System.Data.DataRow ” which means $Qresult is not converted as string properly.
How to convert it into string and store in log file?
You can Convert to
stringeachDataRowlike this:$Qresult = $Qresult| % { $_.$columnName}