Skip to content

Instantly share code, notes, and snippets.

View cbattlegear's full-sized avatar

Cameron Battagler cbattlegear

View GitHub Profile
@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 November 28, 2023 19:59
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."
}
},
# Run this first via Cloud Shell to create your Service Principal and get all the needed information
$sp = New-AzADServicePrincipal -DisplayName "Arc-for-servers" -Role "Owner"
$tenantId= (Get-AzContext).Tenant.Id
$sp.AppId
$sp.PasswordCredentials.SecretText
$tenantId
# Run this locally after all permissions have been set.
$servicePrincipalAppId="Value of $sp.AddId"
@cbattlegear
cbattlegear / dma_csv_list_run.ps1
Created February 28, 2023 16:21
Powershell to do DMA capture for DBMI assessment
# Need two parameters when called, the input CSV list of all servers and the Output folder
# CSV File must be structured like below (Note ServerName,InstanceName header must be included)
# ServerName,InstanceName
# localhost,MSSQLSERVER
param($CsvPath, $OutFolder)
mkdir -p "$OutFolder\SqlAssessments"
@cbattlegear
cbattlegear / Scala UDF in Pyspark.ipynb
Created December 19, 2022 16:52
Showing a scala based UDF being called from PySpark in a Synapse Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cbattlegear
cbattlegear / Mount FS UDF.ipynb
Created December 9, 2022 17:23
Using mssparkutil.fs.mount to read file
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
sudo snap remove docker
sudo apt update && sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common gnupg2
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/docker.gpg
sudo add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
export client_id="YourUserManagedIdentityClientIdGUID"
export DATABRICKS_AAD_TOKEN=$(curl "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d&client_id=$client_id" -H Metadata:true -s | jq -r '.access_token')
databricks configure --aad-token # or you can use the DATABRICKS_AAD_TOKEN env var anywhere else you need to auth!