Skip to content

Instantly share code, notes, and snippets.

@TheCloudScout
Created June 13, 2025 15:39
Show Gist options
  • Save TheCloudScout/40f4d6d9c4fc0f349c014ad85dcef230 to your computer and use it in GitHub Desktop.
Save TheCloudScout/40f4d6d9c4fc0f349c014ad85dcef230 to your computer and use it in GitHub Desktop.
Deploy-SecurityCopilotSCUs.ps1
param (
[string]$ResourceGroupName = "RG-SecurityCopilot",
[string]$CapacityName = "scu-bitdefend-01",
[string]$Location = "westeurope",
[string]$Geo = "EU", # This is the prompt evaluation location. Choose either: EU, US, UK, ANZ
[string]$ApiVersion = "2024-11-01-preview"
)
function Deploy-SecurityCopilotSCUs {
[int]$Units = Read-Host "How many SCUs do you want to deploy?"
[int]$OverageUnits = Read-Host "How many overage SCUs do you want to reserve (can be 0)?"
# Check and register the resource provider if not already registered
$providerNamespace = "Microsoft.SecurityCopilot"
Write-Host "πŸ” Checking if resource provider '$providerNamespace' is registered..."
$provider = Get-AzResourceProvider -ProviderNamespace $providerNamespace
if ($provider.RegistrationState -ne "Registered") {
Write-Host "⚠️ Resource provider '$providerNamespace' is not registered. Registering now..."
Register-AzResourceProvider -ProviderNamespace $providerNamespace
# Wait until it’s registered (poll every 5 sec)
do {
Start-Sleep -Seconds 5
$provider = Get-AzResourceProvider -ProviderNamespace $providerNamespace
Write-Host "⏳ Waiting for provider registration... Current status: $($provider.RegistrationState)"
} while ($provider.RegistrationState -ne "Registered")
Write-Host "βœ… Resource provider '$providerNamespace' registered successfully."
} else {
Write-Host "βœ… Resource provider '$providerNamespace' is already registered."
}
# Ensure resource group exists
if (-not (Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue)) {
Write-Host "Creating resource group $ResourceGroupName..."
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
}
# Define SCU properties
$properties = @{
numberOfUnits = $Units
overageState = "Limited" # or "Unlimited"
overageAmount = $OverageUnits
geo = $Geo
crossGeoCompute = "NotAllowed" # or "Allowed"
}
# Create or update SCU capacity
Write-Host "πŸš€ Deploying SCU capacity '$CapacityName' with $Units units in $Location..."
New-AzResource `
-ResourceType "Microsoft.SecurityCopilot/capacities" `
-ApiVersion $ApiVersion `
-ResourceGroupName $ResourceGroupName `
-ResourceName $CapacityName `
-PropertyObject $properties `
-Location $Location `
-Force
Write-Host "βœ… SCU deployment completed."
}
function Remove-SecurityCopilotSCUs {
Write-Host "πŸ—‘οΈ Removing SCU capacity '$CapacityName'..."
Remove-AzResource `
-ResourceType "Microsoft.SecurityCopilot/capacities" `
-ApiVersion $ApiVersion `
-ResourceGroupName $ResourceGroupName `
-ResourceName $CapacityName `
-Force
Write-Host "βœ… SCU capacity removed."
}
# Ensure Azure context exists ---
if (-not (Get-AzContext)) {
Write-Host "πŸ” No Azure session found. Launching login prompt..."
Connect-AzAccount
} else {
Write-Host "βœ… Azure session found. Using existing context."
}
# Call the deployment function
Deploy-SecurityCopilotSCUs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment