using parameters.json file instead of -TemplateParameterObject in Azure Runbook Arm deployments - azure

In this example here https://learn.microsoft.com/en-us/azure/automation/automation-deploy-template-runbook
They use a -TemplateParameterObject $Parameters for passing parameters to an ARM template. What is the syntax to use a parameters.json file instead?
Deploy the storage account
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile -TemplateParameterObject $Parameters

Just use the -TemplateParameterFile parameter to pass the file:
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile -TemplateParameterFile "yourFilePath"
You can read more about the cmdlet in the New-AzureRmResourceGroupDeployment documentation.

Related

Azure VM templates

So, I exported a VM template and I'm trying to build more VMs based on that template.
How can I define the subscription, resource group and region in the template or in the parameters file?
You can use Azure Powershell to Deploy Virtual Machine, I have reproduced in my environment and followed Microsoft-Document :
Firstly if you donot have a resourcegroup create it using below cmdllet:
New-AzResourceGroup -Name 'rithwik' -Location 'EastUS'
(rithwik- Resourcegroup name)
Then you need to try below cmdlet for deploying VM:
New-AzVm `
-ResourceGroupName 'myResourceGroup' `
-Name 'myVM' `
-Location 'East US' `
-VirtualNetworkName 'myVnet' `
-SubnetName 'mySubnet' `
-SecurityGroupName 'myNetworkSecurityGroup' `
-PublicIpAddressName 'myPublicIpAddress' `
-OpenPorts 80,3389
After giving the command type your username and password as below:
Output:
References of Code taken from:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-powershell#code-try-1
In Portal:

Is it possible to install application while creating Azure VM from PowerShell?

I am trying to create a new Azure VM from PowerShell.
I am currently using the below script to create VM:
$location = "EastUS"
$rgName = "TestRG"
$credential = Get-Credential
New-AzResourceGroup -Name $rgName -Location $location
New-AzVm `
-ResourceGroupName $rgName `
-Name "TestVM" `
-Location $location `
-VirtualNetworkName "TestVnet" `
-SubnetName "TestSubnet" `
-SecurityGroupName "TestNsg" `
-PublicIpAddressName "TestPip" `
-OpenPorts 80,3389 `
-Credential $credential
Can anyone achieve installing applications from PowerShell into Azure VM while creating it? If it's possible, how to do that? Can anyone assist??
Thanks in Advance.
You can not install apllication or add extension to the VM while creating the VM . Once VM will be provisioned then only can only install the application or the add the extension.
You can refer this Micorosoft Document to install the Custom Script Extension Using Set-AzVMExtension.

Configure Function App Private Key binding using PowerShell

I am trying to configure Function App Private Key binding to a Key Vault connection using PowerShell
I can successfully do it with Portal as shown below
I have tried various iterations of the following command against the Function App and the App Service Plan but it seems this is not supported.
Import-AzWebAppKeyVaultCertificate -ResourceGroupName $ResourceGroupName -KeyVaultName $vaultName -CertName $CertName -WebAppName "Don't think this CMDLet Supports Azure Functions"
Can anyone suggest a workaround or the correct CMDLet for this?
When I configure it manually I can see it when I run
Get-AzWebAppCertificate
Managed to get it working with this:
$appServicePlan = Get-AzAppServicePlan -Name $AppServicePlanName -ResourceGroupName $ResourceGroupName;
$PropertiesObject = #{
keyVaultId = $keyVault.ResourceId
keyVaultSecretName = $ADServicePrincipalCertificateName
serverFarmId = $appServicePlan.Id
}
New-AzResource -Name $ADServicePrincipalCertificateName -Location $kv.Location -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/certificates -ApiVersion 2015-08-01 -Force;

Deploy an Azrue VM from an ARM template via Powershell Runbook without downloading template

This article shows a tutorial how to deploy some resources from ARM templates in a powershell runbook. And as I understand, it will download the template and the parameters files in the specific path. But how can that work in an automated Runbook without having any directly attached storage to the automation account. Obviously, I'm misunderstanding something...
I mean the Get-AzureStorageFileContent command:
# Create a new context
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -
StorageAccountKey $StorageAccountKey
Get-AzureStorageFileContent -ShareName 'resource-templates' -Context
$Context -path 'TemplateTest.json' -Destination 'C:\Temp'
$TemplateFile = Join-Path -Path 'C:\Temp' -ChildPath $StorageFileName
# Deploy the storage account
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -
TemplateFile $TemplateFile -TemplateParameterObject $Parameters
Do you know how to understand this, or are there some better methods to reach the goal?
You can use -TemplateParameterUri and -TemplateUri and give publicly available urls that where the tempaltes are stored.

how to get EventHub Namespace SAS keys from powershell

Previously Powershell module AzureRm.EventHub had Get-AzureRmEventHubNamespaceKey and it was easy to get the keys. now it is removed since powershell v5 . Now how can i get the EventHubNameSpace SAS Key. here's the list of powershell Get cmdlets i found in my machine.
Get-AzureRmEventHub
Get-AzureRmEventHubAuthorizationRule
Get-AzureRmEventHubConsumerGroup
Get-AzureRmEventHubGeoDRConfiguration
Get-AzureRmEventHubKey
Get-AzureRmEventHubNamespace
Get-AzureRmIotHubEventHubConsumerGroup
Thanks
You can use Invoke-AzureRmResourceAction to do that:
Invoke-AzureRmResourceAction -ResourceGroupName rgName -ResourceType Microsoft.EventHub/namespaces/AuthorizationRules -ResourceName eventhubName/RootManageSharedAccessKey -Action listKeys -ApiVersion 2015-08-01 -Force

Resources