Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Moore bmoore-msft

View GitHub Profile
@bmoore-msft
bmoore-msft / main.json
Last active Aug 31, 2021
ARM Template using MSI for custom script extension download
View main.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.4.451.19169",
"templateHash": "16656980055364544710"
}
},
@bmoore-msft
bmoore-msft / gist:09c395015e9486c75ddb2f45dc5028b0
Created Jul 30, 2021
deploy a resource with an expression for the type property
View gist:09c395015e9486c75ddb2f45dc5028b0
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"type": {
"type": "string",
"defaultValue": "Microsoft.Network/publicIPAddresses"
}
},
"resources": [
@bmoore-msft
bmoore-msft / Invoke-RESTDeployment.ps1
Last active Jul 16, 2020
Deploy a template using a REST command from the az cli
View Invoke-RESTDeployment.ps1
<#
.Synopsis
This script will deploy an Azure Resource Manager Template using the "az rest" command to invoke the REST api directly
.Description
This script will deploy an Azure Resource Manager Template using the "az rest" command to invoke the REST api directly.
It deploys at resourceGroup scope but can be easily modified for any scope of deployment.
The current account context must already be selected before executing the script, use 'az account show' to show the context
#>
@bmoore-msft
bmoore-msft / Get-ProviderApiVersion.psm1
Last active Jan 14, 2021
Get the api versions and locations for a resource type published in the manifest
View Get-ProviderApiVersion.psm1
function api {
<#
.Synopsis
Get the api versions and locations for a resource type.
.Description
Lists all the available api versions and locations for a given resource type. Information is pulled from the /providers api
which returns the information in the manifest published to ARM.
.Notes
The resource parameter requires the format of Namespace/type, e.g. Microsoft.Storage/storageAccounts
> api Microsoft.Storage/storageAccounts
@bmoore-msft
bmoore-msft / remove-deployments-jobs.ps1
Last active Sep 16, 2019
Delete Deployments from a ResourceGroup Using Jobs and a Service Principal
View remove-deployments-jobs.ps1
#
#this script will delete deployments from a resourceGroup if the number of deployments exceeds the number specified by the Max parameter
#
Param(
[string] [Parameter(Mandatory = $true)] $ResourceGroupName,
[int] [Parameter(Mandatory = $true)] $Max,
[string] [Parameter(Mandatory = $true)] $tenantId,
[string] [Parameter(Mandatory = $true)] $ServicePrincipalId,
[securestring] [Parameter(Mandatory = $true)] $ServicePrincipalSecret,
@bmoore-msft
bmoore-msft / Get-DeploymentCount.ps1
Created May 3, 2019
Get the count of deployments in each resource group in each subscription
View Get-DeploymentCount.ps1
# use this script to get all the deployments in all subscriptions the current user context has access to - it can
# be useful to find groups that are close to the 800 limit
param(
[int]$deploymentCountWarningLevel = 700 # number of deployments where a warning should be written
)
Disable-AzContextAutosave -Verbose
$subs = Get-AzSubscription
@bmoore-msft
bmoore-msft / remove-deployments.ps1
Created Feb 6, 2019
Delete Deployments from a ResourceGroup Based on a Max Number
View remove-deployments.ps1
#
#this script will delete deployments from a resourceGroup if the number of deployments exceeds the number specified by the Max parameter
#
Param(
[string] [Parameter(Mandatory=$true)] $ResourceGroupName,
[int] [Parameter(Mandatory=$true)] $Max
)
$deployments = Get-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName
@bmoore-msft
bmoore-msft / copy-md-blob.ps1
Created Aug 27, 2018
Copies the blob from a managed disk export to another storage account and creates a sasToken for marketplace publishing
View copy-md-blob.ps1
param
(
[string]$sourceBlobUri,
[String]$StorageAccountName,
[string]$StorageAccountResourceGroupLocation,
[String]$StorageContainerName = 'vhds',
[String]$BlobName = 'marketplace.vhd'
)
#get Dest Storage context
@bmoore-msft
bmoore-msft / Verify-DeploymentGuid.ps1
Last active Jun 9, 2021
Fetch the resources tagged in a pid-[GUID] deployment
View Verify-DeploymentGuid.ps1
Param(
[string][Parameter(Mandatory=$true)]$deploymentName, # the full name of the deployment, e.g. pid-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
[string][Parameter(Mandatory=$true)]$resourceGroupName
)
# Get the correlationId of the named deployment
$correlationId = (Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "$deploymentName").correlationId
# Find all deployments with that correlationId
$deployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName | Where-Object{$_.correlationId -eq $correlationId}
@bmoore-msft
bmoore-msft / New-CertificateInKeyVault
Created May 25, 2018
Create a new cert, base64 encode it and put it in KeyVault
View New-CertificateInKeyVault
#Requires -Module AzureRM.KeyVault
# Use this script to create a certificate that you can use to secure a Service Fabric Cluster or other VM/SSL scenario
# This script requires an existing KeyVault that is EnabledFor[Template]Deployment (property depends on the scenario)
# To create a new vault and set the EnabledForDeployment/EnabledForTemplateDeployment property run:
#
# New-AzureRmResourceGroup -Name KeyVaults -Location WestUS
# New-AzureRmKeyVault -VaultName $KeyVaultName -ResourceGroupName KeyVaults -Location WestUS -EnabledForDeployment -EnabledForTempalteDeployment
#
# Once the certificate is created and stored in the vault, the script will provide the parameter values needed for template deployment