How To Run a SQL Query On Multiple SQL Servers Using Powershell

  Рет қаралды 5,696

MS SQL DBA Tech Support

MS SQL DBA Tech Support

2 жыл бұрын

Powershell link:
www.mediafire.com/file/jzeski...

Пікірлер: 14
@sivas842
@sivas842 3 ай бұрын
Thanks to Harsha, it will save a lot of time.
@MSSQLDBATechSupport
@MSSQLDBATechSupport 3 ай бұрын
👍
@Pranilkarki551
@Pranilkarki551 Жыл бұрын
Can you help me with the powershell script that will run a SQL script file to all the database at once.
@MSSQLDBATechSupport
@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
@AnuragIndia
@AnuragIndia 9 ай бұрын
Hi, If you find any info. on executing sql script .sql files through powershell
@MSSQLDBATechSupport
@MSSQLDBATechSupport 6 ай бұрын
I need to reproduce the scenario and need to test the multiple cases and then only i can make a video to public
@kishorKumarGantyala
@kishorKumarGantyala Ай бұрын
@Harsha, Can you please provide PowerShell script
@MSSQLDBATechSupport
@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
@mohammadsiraj5714
@mohammadsiraj5714 2 жыл бұрын
Can you share me your query ?
@MSSQLDBATechSupport
@MSSQLDBATechSupport 2 жыл бұрын
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
@NAVINSUTTLE
@NAVINSUTTLE 2 жыл бұрын
Powershell steps not explained.
@MSSQLDBATechSupport
@MSSQLDBATechSupport 2 жыл бұрын
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
@pdsqsql1493
@pdsqsql1493 5 ай бұрын
@@MSSQLDBATechSupport Could you please share the actual scripts as link is blocking?
@MSSQLDBATechSupport
@MSSQLDBATechSupport 5 ай бұрын
Already download links are there in description
How to Configure Backups in SQL Server Express using OLA Maintenance Solution
5:40
TempDB Sort Spilling (SQL Server Query Tuning)
23:55
SQLMaestros
Рет қаралды 1,5 М.
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 19 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 6 МЛН
PowerShell SQL Tutorial Part 1 : Fetching Data
22:46
JackedProgrammer
Рет қаралды 17 М.
Working with PowerShell to perform SQL tasks
38:19
Randal Root
Рет қаралды 31 М.
Batch File to Execute Multiple SQL Scripts in one go | By SQL Training | By SQL
13:29
SQL Server Linked Servers
12:03
Dashboard Gear
Рет қаралды 16 М.
Use PowerShell to Automate Backing up and Restoring an SQL Database
12:25
AIP IT Solutions
Рет қаралды 1,3 М.
Powershell SQL Connection | Execute Queries
4:58
Database Tales
Рет қаралды 21 М.
PowerShell to Invoke Commands to multiple Servers computers
14:24
Windows PowerShell - How to - Querying Microsoft SQL Server
12:21
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 19 МЛН