Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@SQLvariant
SQLvariant / DockerDesktop-with-SQL-PowerShell-90.ipynb
Last active March 27, 2021 12:14
Create a SQL-on-Linux Docker Container with a Host Mount and Restore the AdventureWorks2016 Database
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / Invoke-DB2Query.ps1
Last active March 27, 2021 12:13
PowerShell function for running a query against a DB2 database.
function Invoke-DB2Query
{
<#
.SYNOPSIS
This function runs a query against a DB2 database.
.DESCRIPTION
This function runs a query against a DB2 database using the account of the user executing the command.
.PARAMETER Server
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / GetStartedWithPowerBIcmdlets.ipynb
Created December 11, 2019 00:42
PowerShell Notebook to get you started with current PowerShell + Power BI capabilities.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / DeploySSIS_ISPac.ps1
Last active December 17, 2020 10:57
Deploy an .ISPAC file to a SSISDB Catalog using the SSIS Provider
# Variables
$TargetFolderName = "ProviderSolution"
$ProjectFilePath = "C:\temp\SSIS\TestSSISSolution\TestSSISProject\bin\Development\TestSSISProject.ispac"
$ProjectName = "TestSSISProject"
# Get the Integration Services catalog
$ProviderCatalog = Get-Item SQLSERVER:\SSIS\localhost\SQL2017\Catalogs\SSISDB\
# Create the target folder
New-Object "Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder" ($ProviderCatalog,
@SQLvariant
SQLvariant / Query_DB2.ps1
Created November 20, 2020 16:12
Uploaded via PowerShell
$dbName="SAMPLE"
$server="not.my.localhost"
#Define connection string for the database
$cn = new-object system.data.OleDb.OleDbConnection("server=$($server);Provider=IBMDADB2;DSN=$($dbName);trusted_connection=true;");
#Define data set for first query
$ds = new-object "System.Data.DataSet" "ds"
#Define query to run
$q = "select * from hello_world"
# Define data object given the specific query and connection string
Get-RsDeploymentConfig -RsProjectFile 'C:\Repos\GitHub\ReportingServicesTools\Tests\CatalogItems\testResources\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj' -ConfigurationToUse Release
FullPath : Release
OverwriteDatasets : False
OverwriteDataSources : False
TargetReportFolder : SQL Server Performance Dashboard
TargetDatasetFolder : /Datasets
TargetDatasourceFolder : /Data Sources
TargetReportPartFolder : Report Parts
TargetServerURL : http://localhost/reportserver
@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
@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 / Build_SQLInstance_wStringCreds.ps1
Created September 29, 2020 17:06
Use Invoke-ExecuteNotebook to build a SQL-on-Linux instance in a Docker container, by calling a Notebook to execute, and passing in the sa_password to the Notebook as a parameter.
Invoke-ExecuteNotebook -InputNotebook .\DockerDesktop-with-SQL-PowerShell-90.ipynb -Parameters @{sa_password = 'Test9999'}