Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@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 / ExtractISPAC_fromSSISDB.ps1
Created May 4, 2019 17:33
Extract an .ISPAC from an SSIS Catalog and write to disk via SSIS PowerShell Provider
<# This is the SSIS Project once it's deployed #>
$Proj = Get-Item 'SQLSERVER:\SSIS\localhost\SQL2017\Catalogs\SSISDB\Folders\ProviderSolution\Projects\TestSSISProject'
$Proj | Get-Member -MemberType Methods
<# This is the theory I have #>
[byte[]] $ProjBytes = $Proj.GetProjectBytes()
[System.IO.File]::WriteAllBytes('C:\temp\ASSISPrj.ispac',$ProjBytes)
<# Dont run this piece of code, you will hate me. #>
$Proj.GetProjectBytes()
@SQLvariant
SQLvariant / Docker-Creation-Notebook.ipynb
Last active June 22, 2019 15:55
Test script for SQL 2019 CTP 3.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / TestContainer64.ipynb
Last active June 22, 2019 00:11
This is the container with the extra volume that won't restore databases. The SQL Notebook includes the error message I'm receiving.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@SQLvariant
SQLvariant / Microsoft.PowerShellISE_profile.ps1
Last active June 23, 2020 13:03
The basic commands I always put in all of my PowerShell $Profile.CurrentUserAllHosts
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 / 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 / ClonePowerBI_WorkspaceUsers.PS1
Last active August 31, 2019 16:12
Copy Users & Groups from one Power BI Workspace to another
<# Clone Users from one Workspace to another
Start by specifying the Target Workspace
Then use the Out-GridView cmdlet to choose the Source Workspce to copy the users & roles from.
https://powerbi.microsoft.com/en-us/blog/announcing-apis-and-powershell-cmdlets-for-power-bi-administrators/ #>
$TargetWorkspace = Get-PowerBIWorkspace -Name 'New QA Workspace';
(Get-PowerBIWorkspace |
Out-GridView -PassThru |
foreach { Get-PowerBIWorkspace -Id $_.Id -Scope Organization }).Users |
WHERE { $_.AccessRight -ne 'Viewer' } |
@SQLvariant
SQLvariant / PBI_ArgumentCompleters.PS1
Last active September 18, 2019 16:02
a few helpful Argument Completers for common Power BI commands, you can ad to your $profile
<# We need an argument completer for -Workspace #>
Register-ArgumentCompleter -ParameterName Workspace -ScriptBlock {
Get-PowerBIWorkspace | ForEach-Object {
$CompletionText = $_.Name
New-Object System.Management.Automation.CompletionResult (
"(Get-PowerBIWorkspace -Name '$($CompletionText)')",
$_.Name,
'ParameterValue',
"$_ (PowerBIWorkspace)"
)
@SQLvariant
SQLvariant / Export O365 PowerBI Audit Log.ps1
Created September 18, 2019 19:47
Exports the PowerBI events from the O365 Audit Log into separate .CSV files for each of the last 90 days.
$UserCredential = Get-Credential 'your.email@somewhere.com'
90..1 |
foreach {
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
$Start=((Get-Date).Date).AddDays(-$_);
Search-UnifiedAuditLog -StartDate $Start -EndDate $Start.AddDays(1) -RecordType PowerBI -ResultSize 5000 |
@SQLvariant
SQLvariant / ExportPBIServiceAssets-toCSV.PS1
Created September 20, 2019 15:40
Export information about Power BI tenant assets to Excel or CSV files
<##################################################################################################>
<#
Export information about assets in the Power BI Tenant to individual CSV files.
#>
<##################################################################################################>
<#
NOTE: You have to be a Power BI Admin to use the -Scope Organization parameter option. #>
<# First, get all the capacities for the tenant, if they have any #>
Get-PowerBICapacity -Scope Organization |