Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Nelson SQLvariant

View GitHub Profile
@SQLvariant
SQLvariant / Mmmm_Chocolatey.ps1
Last active Sep 17, 2020
Install SQL / Data Developer Desktop Tools from Chocolatey
View Mmmm_Chocolatey.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install chocolatey -y
choco install sql-server-management-studio -y
choco install azure-data-studio -y
choco install azuredatastudio-powershell -y
choco install git.install -y
choco install vscode -y
choco install vscode-powershell -y
choco install powerbi -y
@SQLvariant
SQLvariant / SqlAssessment ChecksSQL.ipynb
Created Aug 18, 2020
PowerShell Notebook for working with the Get-SqlAssessmentItem & Invoke-SqlAssessment cmdlets from the SqlServer module.
View SqlAssessment ChecksSQL.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / CellFindingVisitor.cs
Created Aug 11, 2020 — forked from rjmholt/CellFindingVisitor.cs
PowerShell AST visitor to break up a file by comments
View CellFindingVisitor.cs
using System;
using System.Collections.Generic;
using System.Management.Automation.Language;
public class ScriptExtent : IScriptExtent
{
private readonly IScriptPosition _start;
private readonly IScriptPosition _end;
@SQLvariant
SQLvariant / Download_Sample_SQL_Files.ps1
Created Aug 3, 2020
Central file to document & download all the various .SQL files we are testing against.
View Download_Sample_SQL_Files.ps1
<# Change this to the directory you want to download all these .SQL files into #>
cd "$home\Documents\GitHub\Hackathon2020\SQL-to-IPYNB\Sample SQL files"
<# Now go ahead and start downloading. #>
irm https://gist.githubusercontent.com/MsSQLGirl/799d3613c6b3aba58cb4decbb30da139/raw/433ffdcefcbc4db0e5f5c9b53e1e9bde139f885d/SQLSample_01_ServerProperties.sql > '.\SQLSample_01_ServerProperties.sql'
irm https://gist.githubusercontent.com/MsSQLGirl/799d3613c6b3aba58cb4decbb30da139/raw/433ffdcefcbc4db0e5f5c9b53e1e9bde139f885d/SQLSample_02_WWI.sql > '.\SQLSample_02_WWI.sql'
irm https://gist.githubusercontent.com/MsSQLGirl/799d3613c6b3aba58cb4decbb30da139/raw/433ffdcefcbc4db0e5f5c9b53e1e9bde139f885d/SQLSample_03_StringDynamics.sql > '.\SQLSample_03_StringDynamics.sql'
irm https://gist.githubusercontent.com/MsSQLGirl/799d3613c6b3aba58cb4decbb30da139/raw/433ffdcefcbc4db0e5f5c9b53e1e9bde139f885d/SQLSample_04_VariableBatchConundrum.sql > '.\SQLSample_04_VariableBatchConundrum.sql'
irm https://gist.githubusercontent.com/vic
@SQLvariant
SQLvariant / ScriptDOM.ps1
Created Jul 29, 2020
Split .SQL files with ScriptDOM
View ScriptDOM.ps1
<#################################################################################################
Pre-reqs: Install the SqlServer module.
#################################################################################################>
Import-Module -Name SqlServer
Add-Type -LiteralPath "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\Microsoft.SqlServer.TransactSql.ScriptDom.dll"
[Microsoft.SqlServer.TransactSql.ScriptDom.TSql140Parser] $parser = new-object Microsoft.SqlServer.TransactSql.ScriptDom.TSql140Parser($false)
<#################################################################################################
Qucik Helper-function to turn the file into a script fragment, using scriptdom.
#################################################################################################>
function Get-ScriptComments($ScriptPath){
@SQLvariant
SQLvariant / Split_SQL_Files.ps1
Last active Jul 28, 2020
Simple PowerShell script to break apart comment blocks from code blocks, of a .SQL file
View Split_SQL_Files.ps1
$Path = 'c:\temp\sys_databases.sql'
$s = Get-Content -Raw ( Resolve-Path $Path )
#$s.GetType()
<# Doug's code for extracting the comment blocks. #>
$locations=@()
$pos=$s.IndexOf("/*")
while ($pos -ge 0) {
@SQLvariant
SQLvariant / README.md
Last active Jul 9, 2020
Suggestion for PowerShell Extension for VS Code / Azure Data Studio
View README.md

Everyone knows that one of the ‘selling points’ of Jupyter Notebooks is that you can store the results in the Notebook after you have run the code. This is ideal when you have a chance to save the Notebook, or have already completed development of what the code in the Notebook should be. However, when you are still in the middle of developing the code that will ultimately get saved in your Notebook, you may through many iterations of code, before you arrive at your final product. During that process you might want to try things a different way. However, you might end up finding out the other way doesn't work and through that effort you may have broken your code. Now you want to go back several iterations to a good working version.

Idea: What if we could tie Get-History back to a specific cell in the Notebook?

Scenario: Let’s say that a Notebook has 7 code cells, and you’re editing cell #7. You switch from using | foreach {} to use foreach ($Thing in $Things) {…} instead, or maybe even vice ve

@SQLvariant
SQLvariant / Deploy-RsProject.ps1
Last active Jun 23, 2020
I want to get the 'Target...' properties from my deployment configuration.
View Deploy-RsProject.ps1
function Deploy-RsProject
{
<#
.SYNOPSIS
This script deploys a Reporting Services project to a Power BI Report Server.
.DESCRIPTION
This function deploys a full SSRS project to a Power BI Report Server.
.PARAMETER ProjectFile
@SQLvariant
SQLvariant / Microsoft.PowerShellISE_profile.ps1
Last active Jun 23, 2020
The basic commands I always put in all of my PowerShell $Profile.CurrentUserAllHosts
View Microsoft.PowerShellISE_profile.ps1
Import-Module SqlServer;
cd $home\Documents\PoSh\Load\
. .\Get-History2.ps1;
cd C:\temp;
<# First we need an argument completer for -ServerInstance #>
Register-ArgumentCompleter -ParameterName ServerInstance -ScriptBlock {
(dir -Recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\ |
?{ $_.Mode -ne 'd'} |
Group-Object ServerName).Name | ForEach-Object {
$CompletionText = $_
@SQLvariant
SQLvariant / GetStartedWithPowerBIcmdlets.ipynb
Created Dec 11, 2019
PowerShell Notebook to get you started with current PowerShell + Power BI capabilities.
View GetStartedWithPowerBIcmdlets.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.