Code Monkey home page Code Monkey logo

pshell_runtsql's Introduction

PShell_runTSQL

  • Powershell Script to Run Multiple T-SQL Scripts on Multiple SQL Server Instances
  • The script lets you choose whether to store output in a database table or delimited .CSV file.
  • Scripts are/can be dividied into three subcategories; admin/cache/index.

1. Open TSQL_scriptExecution and change the following variables:

$adminServer = "mySqlserver\myInstance"
$reposDB = "myDB"

2. Open SQLServerList.txt and add target servers.

3. Script Execution:

In script root:
.\TSQL_scriptExecution.ps1

Executes with defaults; all output from Scripts\admin and Scripts\cache goes to files (from scripts, log execution results)

PARAMETERS;
  • toTable 1 (inserts output into tables)
  • logToTable 1 (logs execution result into a table)
  • include (commaseparated list to determine which subfolder to look for scripts in - admin,cache, index)

Parameter Defaults

toTable = 1
logToTable = 1
include = (admin, cache)

E.g: .\scriptExecution.ps1 -logToTable 1
(script output to file, log execution result to table)

.\scriptExecution.ps1 -include index, admin
(scripts in Scripts\index and Scripts\admin are run and output to file as is logexecution results)

4. Adding your own scripts to execute

  1. Add T-SQL script to the Scripts folder
  2. If you want script output to tables; add script to create table for the output (NOTE!!! include IF NOT EXIST statement)

Folders:

Scripts (T-SQL scripts to run)
Scripts_CreateTables (scripts that creates tables to hold output; runs if -toTable =1)
Script_Output (script results output folder)
\admin
\cache
\index

(Invoke-Sqlcmd2, Write-DataTable: Supporting cmdlets)

Files:

TSQL_scriptExecution.ps1 (executes T-SQL scripts)
SQLServerList.txt (list of target SQL Server instances)
Create_logScriptExecution.sql (creates execution log table)
Some sample T-SQL Scripts in Script subfolders

Parameters:

[String []])
$include = ("admin","cache"),)
[ValidateSet(“admin",”cache”,"index")])

[Int32] $toTable=0, $logToTable=0

pshell_runtsql's People

Contributors

dataelisabeth avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.