New answers tagged

4

The easiest way to do this (read: least amount of additional code you need to write) is to use Invoke-DbaQuery from the dbatools PowerShell module. Remove the foreach loop - this function will handle it for you. Pass the list of instances into Invoke-DbaQuery and include the -AppendServerInstance switch, and all the instances will be queried and the name of ...


1

You should be able to use this script here to accomplish what you need: https://sql-box.com/2012/10/03/how-to-run-a-sql-query-on-list-of-servers-and-save-output-to-excel-spreadsheet-using-power-shell/


1

Not a direct answer to this question, but as an alternative and certainly very useful, I have followed the advise and link provided by Peter Vandivier in the comments above and doing some changes in the original script, like how to convert to VARBINARY(MAX) and even considered master.dbo.fn_varbintohexstr but it was too slow. Here is the modified script, ...


2

You can output to a pipe-delimited file by piping the output to Export-Csv and specifying the delimiter as a pipe. invoke-sqlcmd -ServerInstance <server_name> -Database <database_name> -query "<query>" ` | Export-Csv -Delimiter "|" -Path "U:\temp\export.csv"


2

The message that is returned is not accurate as it is referring to the name that it will give the network name resource (SQLPROD_AG_SQLPROD), and it is labelled incorrectly as the DNS name. You can see that the network name resource in your AG is named SQLPROD_AG_SQLPROD, and that is what it's referring to. It really should say something like, "The ...


1

Thanks to @Tony Hinkle for giving an answer as a comment. Here it is promoted to an actual answer, so hopefully the next person with this question finds it: I created a table in my "Automation" database named "ImportRowCount" with one column named "RowCount" and inserted a single row in there with the number 0 Next, I added this line to my Powershell ...


Top 50 recent answers are included