Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Nelson SQLvariant

View GitHub Profile
@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 / README.md
Last active Jul 10, 2020
I wish there was some kind of -GridThru functionality (`Out-GridView` with `-PassThru`) built into the Get-History command
View README.md

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 / 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 / PBIRS_ArgumentCompleter.PS1
Created May 13, 2020
PowerShell Argument Completer for SSRS & Power BI Report Server
View PBIRS_ArgumentCompleter.PS1
<# 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 / 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.
@SQLvariant
SQLvariant / Copy_PowerBI_WorkspaceItems.ipynb
Created Dec 11, 2019
Different options for copying items in a Power BI Workspace.
View Copy_PowerBI_WorkspaceItems.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.