Commit 22a53bb4 authored by carplaptop's avatar carplaptop

final commits on succinct branch

parent 4c1af6c3
################################################################################
# BuildSQL.ps1
#
# This PoSH script will merge all .sql files in the folder that this .ps1 file is found, and all
# subdirectories. Specifically it runs the FILES first, then the FOLDERS in the given directory,
# alphabetically.
# Any folder prefaced with "_" (underscore) is skipped (including sub folders and files)
#
# To Execute:
# cd to the directory with BuildSQL.ps1
# powershell .\BuildSQL.ps1
#
# Output:
# PerformanceCollectorInstaller.sql. This file will contain all objects for PerformanceCollector
#
# System Requirements:
# As with any PoSH script, you may need to run powershell Set-ExecutionPolicy Unrestricted first
# MD3 requires sqlcmd to be in PATH, so you'll need to run this from a machine that has SQL installed on it.
#
################################################################################
cls
# Always fail the PoSH script on ANY error
$script:ErrorActionPreference = "Stop"
$workingDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$CurrentSQLScriptDirectory = $workingDirectory
$ScriptFile = "PerformanceCollectorInstaller.sql"
$ScriptFilePath = (Join-Path $workingDirectory $ScriptFile)
################################################################################
# Helper Functions
################################################################################
function Recurse-Folders {
param (
[Parameter(Position=0, Mandatory=$true)] [string]$folderspec
)
## new method
[string]$MergedOutput = "`n"
# within a folder, process FILES first, then subfolders
foreach ($sqlScript in Get-ChildItem -Path $folderspec -Filter "*.sql" | Sort-Object Name) {
$sqlScript = $sqlScript.FullName
$MergedOutput += "`n GO `n"
$MergedOutput += "`n GO `n"
$MergedOutput += [System.IO.File]::ReadAllText("$sqlScript")
$MergedOutput += "`n GO `n"
}
# Append this code to existing ScriptFile
$MergedOutput | Out-File -Encoding "Unicode" -FilePath $ScriptFilePath -Append
# now, starting with folderspec, traverse the directory tree , skip all folders that start with _ (underscore)
foreach ($subfolder in (Get-ChildItem $folderspec | Where-Object {$_.PSIsContainer -and $_.Name -notlike "_*"}) | Sort-Object Name){
$subfolder = $subfolder.FullName
Recurse-Folders $subfolder
}
}
################################################################################
# Main
################################################################################
Try
{
[int]$exitCode = 0
# Run the "master only" script
# RunCreateDbScript
# Prepare the ScriptFile
"`n" | Out-File -Encoding "Unicode" -FilePath $ScriptFilePath -Force
# Merge all .sql files, then subfolders, alphabetically
Recurse-Folders $CurrentSQLScriptDirectory
$exitCode = 0
}
Catch
{
Write-Host "Error running script: $sqlScript" -ForegroundColor Red
# Loop through all errors
$currentException = $_.Exception
While ($currentException) {
Write-Host $currentException.Message
$lastException = $currentException
if ($currentException.GetType().Name -eq "SqlException") {break}
$currentException = $currentException.InnerException
}
Write-Host "Error: deployment FAILED" -ForegroundColor Red
$exitCode = 1
}
Finally {
$script:ErrorActionPreference = "SilentlyContinue"
foreach ($err in $Error) {Throw $err}
Exit $exitCode
}
\ No newline at end of file
......@@ -7,14 +7,9 @@ This utility captures a series of performance metrics and logs them to various t
How to Install Performance Collector
=======================================
Prerequisites
--------------
1. Ensure SQL Agent is running. If it isn't PerformanceCollector won't work correctly.
2. Ensure you run the installer script as sysadmin.
1. create the PerformanceCollector database on your server using your preferred file layouts. If you don't do this the Installer script will do this for you using the default data file and log placement.
3. create the PerformanceCollector database on your server using your preferred file layouts. If you don't do this the Installer script will do this for you using the default data file and log placement.
How Does Performance Collector Work?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment