Skip to content

Instantly share code, notes, and snippets.

View cbattlegear's full-sized avatar

Cameron Battagler cbattlegear

View GitHub Profile
@cbattlegear
cbattlegear / Test-SPProfileThrottling.ps1
Created February 24, 2026 17:00
Quick way to test if Service Principal Profiles get individual throttling limits
<#
.SYNOPSIS
Tests Power BI API throttling behavior across service principal profiles.
.DESCRIPTION
1. Authenticates with a service principal (client credentials).
2. Creates two service principal profiles via the Power BI Profiles API.
3. Calls the Get Datasets API using Profile 1 until throttled N times consecutively.
4. Switches to Profile 2 and tests whether the request succeeds without throttling.
param(
[Parameter(Mandatory=$true)]
[string]$ReportId,
[Parameter(Mandatory=$false)]
[string]$BearerToken
)
# Prompt for token if not provided
if ([string]::IsNullOrEmpty($BearerToken)) {
$filteredPolicies = New-Object System.Collections.ArrayList
$policies = Get-AzResource -ResourceType "Microsoft.Network/networkIntentPolicies"
foreach ($policy in $policies) {
$Id = $policy.ResourceId
$response = Invoke-AzRestMethod -Method "GET" -Uri "https://management.azure.com$($Id)?api-version=2021-02-01"
$responseObj = $response.Content | ConvertFrom-Json
$policyInfo = [PSCustomObject]@{ Id = $responseObj.id; Subnet = ""; Orphaned = $false; }
if ($responseObj.properties.PSObject.Properties.Match("subnets").Count -gt 0) {
@cbattlegear
cbattlegear / pause_fabric.ps1
Created February 4, 2025 15:29
Automatically Pause All Fabric Capacities
Param(
[Parameter(Mandatory=$false)]
[string]$subscriptionID = "YourSubscriptionIDHere",
[Parameter(Mandatory=$false)]
[ValidateSet("suspend", "resume")]
[string]$operation = "suspend",
[Parameter(Mandatory=$false)]
[string]$suspendAPIVersion = "api-version=2023-11-01"
select
db_name(database_id) as database_name,
[size_in_MiB] = CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)),
CASE
WHEN CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)) <= 132096 THEN 500 -- If less than or equal to 129 GiB
WHEN CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)) > 132096 AND CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)) <= 525312 THEN 2300 -- If more than 129 GiB but less than or equal to 513 GiB
WHEN CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)) > 525312 AND CAST([size] * 8 / 1024.0 AS DECIMAL(10,2)) <= 1049600 THEN 5000 -- if more than 513 GiB but less than 1025 GiB
ELSE 7500 -- Any more than 1025 GiB and you get 7500
END as file_iops
from sys.master_files
CREATE EVENT SESSION [FailedQueries] ON SERVER
ADD EVENT sqlserver.error_reported
(ACTION(sqlserver.client_app_name, sqlserver.client_hostname,
sqlserver.database_name, sqlserver.sql_text, sqlserver.username)
WHERE ([package0].[greater_than_int64]([severity], (10)) AND client_app_name='SQLExternalMonitoring'))
WITH (STARTUP_STATE = ON)
GO
@cbattlegear
cbattlegear / AHUB for PaaS.kql
Last active January 26, 2024 19:53
Resource Graph Queries for AHUB on SQL VMs
resources
| where type == "microsoft.sql/servers/databases" or type == "microsoft.sql/managedinstances" or type == "microsoft.sql/servers/elasticpools"
| where properties.licenseType == "LicenseIncluded"
| extend SqlEdition = case(sku.name hasprefix_cs "GP_", "Standard", sku.name hasprefix_cs "HS_", "Standard", sku.name hasprefix_cs "BC_", "Enterprise", "Unknown")
| extend vCores = toint(sku.capacity)
| extend licensesNeeded = toint(round(vCores/2))
| project licensesNeeded, vCores, SqlEdition
| summarize sum(licensesNeeded) by SqlEdition
$allRecommendations = New-Object -TypeName "System.Collections.ArrayList"
Get-AzSubscription | ForEach-Object {
$sub = $_
Set-AzContext -SubscriptionId $_.Id
$recommendations = Get-AzSqlServer | Get-AzSqlDatabase | Where-Object Edition -ne "System" | Get-AzSqlDatabaseSensitivityRecommendation
$recommendations | ForEach-Object {
$dbinfo = $_
$_.SensitivityLabels | ForEach-Object {
$newRecommandation = $_ | Select-Object @{label = 'SubscriptionId'; expression = {$sub.Id}}, @{label = 'ResourceGroupName'; expression = {$dbinfo.ResourceGroupName}}, @{label = 'ServerName'; expression = {$dbinfo.ServerName}}, @{label = 'DatabaseName'; expression = {$dbinfo.DatabaseName}}, *
$allRecommendations.Add($newRecommandation)
@cbattlegear
cbattlegear / esuresourcegraph.kql
Last active May 14, 2024 18:58
Azure Resource Graph Query
resources
| where type == "microsoft.hybridcompute/machines"
| where properties.osName == "windows"
| extend joinId = tolower(id)
| join kind = leftouter (
resources
| where type == "microsoft.azurearcdata/sqlserverinstances"
| extend arcMachineId = tolower(tostring(properties.containerResourceId))
| extend sqlVersion = tostring(properties.version)
| extend vCores = toint(properties.vCore)
@cbattlegear
cbattlegear / gist:615ebe348add4e65d43f795f6dfb518b
Created May 3, 2023 20:33
SQL Licensing Workbook ARM Template
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
"defaultValue": "SQL Licensing Summary",
"metadata": {
"description": "The friendly name for the workbook that is used in the Gallery or Saved List. This name must be unique within a resource group."
}
},