Skip to content

Instantly share code, notes, and snippets.

View SQLvariant's full-sized avatar

Aaron Nelson SQLvariant

View GitHub Profile
@SQLvariant
SQLvariant / Export_PowerPlatform_Gateway_Assets.ipynb
Created December 10, 2019 22:24
Export details of your PowerPlatform Gateway assets from your entire tenant.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / 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 / GatewayClusters.ps1
Last active February 12, 2024 12:12
Get the Governance Data You Need Out of Your Power BI Gateways with PowerShell
<# Make sure you have the modules installed.
You only need the ImportExcel module if you want to export the results to Excel files. #>
Install-Module DataGateway
Install-Module ImportExcel
<# Discovery #>
# All Gateway Clusters in your tenant.
Get-DataGatewayCluster -Scope Organization
# All nodes of all Gateway Clusters in your tenant.
@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 / 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 / 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 / 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 |
@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 |