Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@SQLvariant
SQLvariant / PBIRS_ArgumentCompleter.PS1
Created May 13, 2020 15:38
PowerShell Argument Completer for SSRS & Power BI Report Server
<# SSRS / PBIRS #>
Register-ArgumentCompleter -ParameterName ReportServerUri -ScriptBlock {
"http://localhost:8016/Reports_SQL2016", 'http://localhost:8081/PBIRServer' | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (SSRSInstance)"
)
@SQLvariant
SQLvariant / Deploy-RsProject.ps1
Last active June 23, 2020 22:03
I want to get the 'Target...' properties from my deployment configuration.
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 / README.md
Last active October 11, 2020 19:06
I wish there was some kind of -GridThru functionality (`Out-GridView` with `-PassThru`) built into the Get-History command

Please 'Code Golf' this snippet

I like to get my code 'working' and then see if I can shorten the code, make it run faster, or maybe just reduce the number of variables I'm using.

However, sometimes I end up breaking things. At which point, I want to jump back to a version of the code that executed successfully. To do that, I sometimes use the code block below:

Get-History |
SELECT * |
Out-GridView -PassThru |
foreach { $_.CommandLine } | clip
@SQLvariant
SQLvariant / README.md
Last active July 9, 2020 13:12
Suggestion for PowerShell Extension for VS Code / Azure Data Studio

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 / Split_SQL_Files.ps1
Last active July 28, 2020 18:02
Simple PowerShell script to break apart comment blocks from code blocks, of a .SQL file
$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 / ScriptDOM.ps1
Created July 29, 2020 18:53
Split .SQL files with ScriptDOM
<#################################################################################################
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 / Download_Sample_SQL_Files.ps1
Created August 3, 2020 16:05
Central file to document & download all the various .SQL files we are testing against.
<# 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 / CellFindingVisitor.cs
Created August 11, 2020 18:20 — forked from rjmholt/CellFindingVisitor.cs
PowerShell AST visitor to break up a file by comments
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 / SqlAssessment ChecksSQL.ipynb
Created August 18, 2020 01:40
PowerShell Notebook for working with the Get-SqlAssessmentItem & Invoke-SqlAssessment cmdlets from the SqlServer module.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / Download_Notebook.ps1
Last active October 15, 2020 12:12
Example PowerShell Notebook to show you examples of what will happen when you use the ConvertTo-SQLNoteBook function.
irm https://gist.githubusercontent.com/SQLvariant/5cbad3dd52093fbd053ec46769a0fc22/raw/1ecf6c292a6c0b9419af01d7360d373a2adff3cd/Using_ConvertTo-SQLNoteBook.ipynb -OutFile Using_ConvertTo-SQLNoteBook.ipynb