Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@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 / 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 / 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_PBIAuditLogs_toDailyJson.ps1
Last active October 3, 2019 22:08
Export Power BI Audit Logs to .JSON files
90..1 |
foreach {
$Date = (((Get-Date).Date).AddDays(-$_))
$StartDate = (Get-Date -Date ($Date) -Format yyyy-MM-ddTHH:mm:ss)
$EndDate = (Get-Date -Date ((($Date).AddDays(1)).AddMilliseconds(-1)) -Format yyyy-MM-ddTHH:mm:ss)
Get-PowerBIActivityEvent -StartDateTime $StartDate -EndDateTime $EndDate -ResultType JsonString |
Out-File -FilePath "c:\temp\PowerBIAuditLogs\PowerBI_AudititLog_$(Get-Date -Date $Date -Format yyyyMMdd).json"
}
@SQLvariant
SQLvariant / Import_HundredsOf_CSVs.PS1
Created October 10, 2019 20:42
Basic script to import every .CSV file from a directory and INSERT each one into it's own table in SQL Server. It will create the table if it doesn't exist.
dir -Filter *.csv |
foreach {
"$($_.Name)";
,(Import-Csv -Path $_.Name) |
Write-SqlTableData -ServerInstance localhost\SQL2017 -DatabaseName BlankDB -SchemaName dbo -TableName $_.BaseName -Force
}
@SQLvariant
SQLvariant / DeadSimple_PSResults_Lag.ipynb
Created December 6, 2019 18:26
Examples of lagging results in PowerShell Notebooks with v0.1.2 of the powershell_kernel
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / ExportPowerBIWorkspaceAssets_withPowerShell.ipynb
Created December 10, 2019 18:31
PowerShell Notebook (open in Azure Data Studio) to help you export all of your Power BI Workspace Asset information.
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 December 11, 2019 00:37
Different options for copying items in a Power BI Workspace.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.