Push to SQL Server

</pre>
# Local Variables
$base_path = "C:\Temp"
$local_repo_name = "Blitz"
$local_repo_directory = $base_path + "\" + $local_repo_name
 
# Remote Variables
$remote_repo_url = "https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit.git"
$branch_name = "master"
 
# Git commands
$clone_cmd = "git clone " + $remote_repo_url + " --branch " + $branch_name + " " + $local_repo_name;
$merge_cmd = "git pull origin"
$branch_check_cmd = "git ls-remote --heads " + $remote_repo_url + " " + $branch_name
 
# Change the working directory
CD $base_path
 
# Check the existence of the remote repo and capture the number of rows that match
# in the result set of the query in $branch_check_cmd.
# Then clone or merge, depending if the local repo exists.
$number_of_matches = Invoke-Expression $branch_check_cmd | Measure-Object
 
IF ( $number_of_matches.Count -eq 1 ) {
 
IF ( -not (Test-Path( $local_repo_name )) ) {
 
# The local repo does not exist, let's grab a copy
Invoke-Expression $clone_cmd
CD $local_repo_name
 
} ELSE {
 
# The local repo exists, commence merge to pull in most recent changes
CD $local_repo_name
Invoke-Expression $merge_cmd
 
}
 
# Database Variables
$instance_name = "localhost\sql16"
$database_name = "master"
 
# Retrieves SQL scripts that match desired criteria and executes them in the target database
Get-ChildItem |
 
Where-Object { ($_.Name -eq "sp_Blitz.sql") } |
 
ForEach-Object {Invoke-Sqlcmd -ServerInstance $instance_name -Database $database_name -QueryTimeout 65535 -InputFile $_.FullName}
 
} ELSE {
 
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Crap, something went wrong.",0,"Error",0x1)
 
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source