Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@SQLvariant
SQLvariant / AdventureWorks_Tables.ipynb
Last active July 21, 2022 18:47
Simple example of running a query against the AdventureWorks db and storing the results in a Jupyter Notebook.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / Read_ADF_LinkedService_Contents.ps1
Created July 15, 2022 20:14
PowerShell script to read info out of Linked Services .JSON files on your local machine.
# > Before you begin, navigate to a local directory containing the Linked Services files from your ADF
c:\temp\ADF\linkedService
# First, run through all of the ADF LinkedService files to extract all the pieces of the connection information we're loking for.
$LinkedServices = @()
$LinkedServiceFiles = dir -Filter *.json
foreach($LinkedServiceFile in $LinkedServiceFiles){
$LinkedServiceContents = Get-Content -Path $LinkedServiceFile | ConvertFrom-Json -Depth 20
switch($LinkedServiceContents.properties.type){
'AzureSqlDatabase' {$Connection = $LinkedServiceContents.properties.typeProperties.connectionString}
'AzureSqlDW' {$Connection = $LinkedServiceContents.properties.typeProperties.connectionString}
@SQLvariant
SQLvariant / Invoke-SqlNotebook.md
Last active May 27, 2022 09:53
3 different options for using the Invoke-SqlNotebook cmdlet

Use with Registered Servers

Use Registered Servers or Central Management Server to run Invoke-SqlNotebook against multiple servers.

$datetime = Get-Date -Format yyyyMMddhhmm

dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' |
WHERE { $_.Mode -ne 'd'} |            
foreach {
@SQLvariant
SQLvariant / Get-SqlChange.ps1
Last active May 12, 2022 18:00
Simple PowerShell function to wrap the SQLPackage.exe command for deployment automation
function Get-SqlChange
{ <#
.SYNOPSIS
This command runs SQLPackage.exe to compare a .DACPAC file to a database and generate a file.
.DESCRIPTION
This command runs SQLPackage.exe to compare a .DACPAC file to a database and generate a either a DeployReport or SQL change file.
.PARAMETER Action
Specify the action, currently only "DeployReport" and "Script" are supported.
@SQLvariant
SQLvariant / Invoke-DaxQuery.Test.ps1
Last active April 19, 2022 07:47
PowerShell function to run a DAX query against a Power BI Repot / Analysis Services, and accompanying Pester test (which requires a separate .PBIX file that I haven't published yet)
Describe "Invoke-DaxQuery" {
Context "Invoke a DAX Query and test the result"{
# Run queries and compare them
$results = Invoke-DaxQuery -DAXQuery "EVALUATE ReportCatalogQuery"
# Test if the config was retrieved
It "Should verify the count is correct by comparing against a static number" {
@($results).Count | Should -Be 36
}
@SQLvariant
SQLvariant / Export_PBI_AuditLogs.ipynb
Created December 10, 2019 19:22
PowerShell Notebook showing how to use both cmdlets available for extracting Power BI audit log events
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / Out-DataTable.ps1
Created August 3, 2021 12:47
v1.1 of Chad Miller's Out-DataTable PowerShell function
#######################
<#
.SYNOPSIS
Creates a DataTable for an object
.DESCRIPTION
Creates a DataTable based on an objects properties.
.INPUTS
Object
Any object can be piped to Out-DataTable
.OUTPUTS
@SQLvariant
SQLvariant / CopyReport_PreserveDatasetConnection.ps1
Last active March 26, 2022 14:36
Promote a Power BI Report from a QA Workspace to a Prod Workspace, while preserving the connection to the Prod database when the updated report lands in the Prod Workspace.
$source_workspace_ID = (Get-PowerBIWorkspace -Name 'QA-Workspace').Id
$report = Get-PowerBIReport -Name 'Regional Sales' -WorkspaceId $source_workspace_ID
$target_workspace_ID = (Get-PowerBIWorkspace -Name 'Prod-Workspace').Id
$targetReport = Get-PowerBIReport -Name 'Regional Sales' -WorkspaceId $target_workspace_ID
Copy-PowerBIReport -Report $report -WorkspaceId $source_workspace_ID -TargetWorkspaceId $target_workspace_ID -TargetDatasetId ($targetReport).DatasetId -OutVariable NewReport
<# Now to remove the old version of the report in the Prod workspace #>
#$url = 'https://api.powerbi.com/v1.0/myorg/groups/' + $target_workspace_ID + '/reports/' + $targetReport.Id
#Invoke-PowerBIRestMethod -Method Delete -Url $url
@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 / 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)"
)