Hi all, I am having fun trying to get a PowerShell called database integrity check to output to a file. This is so I can then search the output for specific lines/words to reduce the ammount to be read.This works:[code="other"]& sqlcmd -S $servername -E -Q "dbcc checkdb(N'$($dbName)') with all_errormsgs" >"$($ResultFile)"[/code]but it feels like cheating when there is Invoke-Sqlcmd but I cannot get Invoke-Sqlcmd to produce the output to file.This produces an empty file:[code="other"]Invoke-Sqlcmd -ServerInstance $servername -Query "dbcc checkdb(N'$($dbName)') with all_errormsgs" | out-file "$($ResultFile)"[/code]The following produces an error about not recognising -ServerInstance (I guess it is linking the switch to Add-Content)[code="other"]Add-Content $ResultFile Invoke-Sqlcmd -ServerInstance $servername -Query "dbcc checkdb(N'$($dbName)') with all_errormsgs"[/code]So I put the Invoke-Sqlcmd into bracers but this only produces an empty result file.[code="other"]Add-Content $ResultFile (Invoke-Sqlcmd -ServerInstance $servername -Query "dbcc checkdb(N'$($dbName)') with all_errormsgs")[/code]For the times that do not produce an error, time does pass before the prompt comes back so I guess it is performing the check.Does anyone know how to get Invoke-Sqlcmd to output to a file, or should I give up and use the command prompt code (which works).
↧