Can you help me with the powershell script that will run a SQL script file to all the database at once.
@MSSQLDBATechSupport Жыл бұрын
One thing i need to tell i am a dba where i am little knowledge on powershell, however we can achieve you requirement using SP_MSFOREACHDB stored proceddure
@AnuragIndia9 ай бұрын
Hi, If you find any info. on executing sql script .sql files through powershell
@MSSQLDBATechSupport6 ай бұрын
I need to reproduce the scenario and need to test the multiple cases and then only i can make a video to public
@kishorKumarGantyalaАй бұрын
@Harsha, Can you please provide PowerShell script
@MSSQLDBATechSupportАй бұрын
# Script Runs on servers listed in serverlist.txt # use sqlps.exe to run this script # In cmd, sqlps.exe c:\scripts\script.ps1 $query = "select @@VERSION" #Path to the excel file to be saved. $csvFilePath = "c:\testing\queryresults.csv" $excelFilePath = "c:\testing\queryresults.xls" # Run Query against multiple servers, combine results # Replace "Server1", "Server2\INSTANCE1" with names of your SQL Server instances $instanceNameList = get-content C:\serverlist.txt $results=@() foreach($instanceName in $instanceNameList) { write-host "Executing query against server: " $instanceName $results += Invoke-Sqlcmd -Query $query -ServerInstance $instanceName } # Output to CSV write-host "Saving Query Results in CSV format..." $results | export-csv $csvFilePath -NoTypeInformation # Convert CSV file to Excel # Reference : gallery.technet.microsoft.com/scriptcenter/da4c725e-3487-42ff-862f-c022cf09c8fa write-host "Converting CSV output to Excel..." $excel = New-Object -ComObject excel.application $excel.visible = $False $excel.displayalerts=$False $workbook = $excel.Workbooks.Open($csvFilePath) $workSheet = $workbook.worksheets.Item(1) $resize = $workSheet.UsedRange $resize.EntireColumn.AutoFit() | Out-Null $xlExcel8 = 56 $workbook.SaveAs($excelFilePath,$xlExcel8) $workbook.Close() $excel.quit() $excel = $null write-host "Results are saved in Excel file: " $excelFilePath
@mohammadsiraj57142 жыл бұрын
Can you share me your query ?
@MSSQLDBATechSupport2 жыл бұрын
In the description you can find mediafire link,anyhoo i am giving here as well. www.mediafire.com/file/jzeskiktjtfa2r3/how+to+run+single+sql+server+query+on+multiple+sql+servers.ps1/file
@NAVINSUTTLE2 жыл бұрын
Powershell steps not explained.
@MSSQLDBATechSupport2 жыл бұрын
Hello Navin, i have shown you where we need to replace the values. I don't want dig more in other technologies. other wise it will lead unnecessary headache. Thanks Admin
@pdsqsql14935 ай бұрын
@@MSSQLDBATechSupport Could you please share the actual scripts as link is blocking?