I am trying to do the following:
Capture the original Edition and RequestedServiceObjectiveName of an Azure sql database using the following PS script:
$OriginalScale= Get-AzSqlDatabase `
-ResourceGroupName "POC_Scale" `
-ServerName "scaledb" `
-DatabaseName "scaleME"
2.Scale up this database to a particular edition and tier using:
Set-AzSqlDatabase `
-ResourceGroupName "POC_Scale" `
-ServerName "scaledb" `
-DatabaseName "scaleME" `
-Edition "Standard" `
-RequestedServiceObjectiveName "S3" `
3.After deployment, scale it back to the original scale that I had captured prior to step 2 using:
Set-AzSqlDatabase `
-ResourceGroupName "POC_Scale" `
-ServerName "scaledb" `
-DatabaseName "scaleME" `
-Edition "$OriginalScale.Edition" `
-RequestedServiceObjectiveName "$OriginalScale.RequestedServiceObjectiveName" `
I get the following error:
I have tried the following:
Tried to use single quotes around the -Edition and -RequestedServiceObjectName being passed in but I get the same error.
Checked that the $OriginalScale.Edition does indeed return "Standard". Also checked docs and found that .Edition is actually a string which should theoretically work.
Can someone please guide me on what I'm doing wrong here. Seems simple but not sure what I'm doing wrong.
The quotes are the problem. Either don't use the quotes, or do it like this:
-Edition "$($OriginalScale.Edition)"
The syntax you're currently trying is ignoring the .Edition and only outputting the PSObject name.
Related
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:
When I'm trying to run the command New-AzureRmSqlDatabaseExport in an PowerShell Runbook it fails with the error message:
New-AzureRmSqlDatabaseExport : Object reference not set to an instance of an object.
I have verified that all modules are updated, AzureRM.Sql has version 4.12.1 when I'm writing this. New-AzureRmSqlDatabaseExport is a part of AzureRM.Sql and is also available in the runbook editor.
What I'm missing?
Update: The code I'm trying to run looks something like this:
$exportRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName "MyResourceGroup" -ServerName "MyServerName" -DatabaseName "MyDatabaseName" -StorageKeytype StorageAccessKey -StorageKey "MyStorageKey" -StorageUri "https://mystorage.blob.core.windows.net/backupdb/db.bacpac" -AdministratorLogin "userName" -AdministratorLoginPassword (ConvertTo-SecureString "mypassword" -AsPlainText -Force)
It does work Azure Cloud Shell.
Before the command is executed, make sure that you are authenticated. Adding these lines before the command will solve this problem:
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzureRmAccount -ServicePrincipal -Tenant $connection.TenantID `
-ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint
You find more information here:
https://learn.microsoft.com/en-us/azure/automation/automation-first-runbook-textual-powershell
According to MS's docs for New-AzureRmHDInsightCluster,
it should accept -ComponentVersion as an option:
$httpCredential = New-Object System.Management.Automation.PSCredential ($httpUserName, $clusterpassword)
$sparkConfig = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
$sparkConfig.Add("spark", "2.1")
New-AzureRmHDInsightCluster `
-ClusterName mycluster `
-ComponentVersion $sparkConfig `
-ClusterSizeInNodes 4 `
-HttpCredential $httpCredential `
-Location "Central US" `
-OSType Linux `
-ResourceGroupName tstcluster
However, this command results in:
##[error]A parameter cannot be found that matches parameter name 'ComponentVersion'.
Is there a way to select the Spark version required? We used to use:
Add-AzureRmHDInsightComponentVersion -Config $config -ComponentName "Spark" -ComponentVersion "2.1"
But that's now rejected:
##[error]The term 'Add-AzureRmHDInsightComponentVersion' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
EDIT:
A couple of factors that were key to solving this: First, this script is run by an Azure PowerShell Script task in an Azure Dev Ops pipeline. Second, the PowerShell version used to run this script was 1.*.
Try the command below, it works fine on my side. Make sure you have installed the AzureRM.HDInsight powershell module, you could check it with Get-Module AzureRM.HDInsight.
Sample command:
$httpUserName = "joyhd"
$clusterpassword = ConvertTo-SecureString "<password>" -AsPlainText -Force
$httpCredential = New-Object System.Management.Automation.PSCredential($httpUserName, $clusterpassword)
$SshCredential = New-Object System.Management.Automation.PSCredential($httpUserName, $clusterpassword)
$storageAccountName = "<storageAccountName>"
$storageAccountKey = "xxxxxxx"
$storageContainer = "testhd"
New-AzureRmHDInsightClusterConfig `
| Add-AzureRmHDInsightComponentVersion `
-ComponentName "Spark" `
-ComponentVersion "2.1" `
| New-AzureRmHDInsightCluster `
-ClusterName joytesthd `
-ClusterType "Spark" `
-ClusterSizeInNodes 4 `
-HttpCredential $httpCredential `
-Location "eastus" `
-OSType Linux `
-ResourceGroupName joywebapp `
-DefaultStorageAccountName "$storageAccountName.blob.core.windows.net" `
-DefaultStorageAccountKey $storageAccountKey `
-DefaultStorageContainer $storageContainer `
-SshCredential $SshCredential
Result:
MS was not able to explain why a script that worked in Azure Dev Ops (then VSTS) stopped working. That is, why Add-AzureRmHDInsightComponentVersion was supported in January 2018 but not in September of that same year.
Their solution was to select the latest version of PowerShell available in a pipeline (3.*) and set the Preferred Azure PowerShell Version to 3.8.0.
Making those changes made the existing script workable again.
Anyone aware of cmdlet for creating API App in powershell? I tried searching for it, but couldn't find anything. I think New-AzureRmWebApp is way to go by passing some type, has anyone idea about it?
As mentioned by evilSnobu in this link it worked with slight modification. So I am posting the answer if someone needs it.
# CREATE "just-an-api" API App
$ResourceLocation = "West US"
$ResourceName = "just-an-api"
$ResourceGroupName = "demo"
# If we want to create under a specific app plan, we need to pass the server farmid in format
$serverFarmId = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.Web/serverfarms/<app_service_plan_name>;
#If nothing is passed inside $PropertiesObject, it create s default app service plan.
$PropertiesObject = #{"serverFarmId"=$serverFarmId}
New-AzureRmResource -Location $ResourceLocation `
-PropertyObject $PropertiesObject `
-ResourceGroupName $ResourceGroupName `
-ResourceType Microsoft.Web/sites `
-ResourceName "just-an-api" ` #removing $ResourceName, as either one is required.
-Kind 'api' `
-ApiVersion 2016-08-01 -Force
Lightly related to How to add an SSL certificate to an azure website using powershell?
I am trying to add a certificate to an Azure RM website via Powershell.
I don't think there is a direct Azure Powershell command, and it will need to be done via New-AzureRmResource
In the latest release of Azure PowerShell v 1.1.0, there is a number of new commands to handle SSL certificates in Azure Web Apps
You can upload the certificate and bind it to hostname using
New-AzureRmWebAppSSLBinding -ResourceGroupName myresourcegroup -WebAppName mytestapp -CertificateFilePath PathToPfxFile -CertificatePassword PlainTextPwd -Name www.contoso.com
And then remove the binding but without removing the certificate, the app should be able to use it after you add a app setting referencing that cert (this should be done using the portal - the PowerShell command to do so will come soon - No ETA for now)
Remove-AzureRmWebAppSSLBinding -ResourceGroupName myresourcegroup -WebAppName mytestapp -Name www.contoso.com -DeleteCertificate $false
Looking through the ARM Template the "Microsoft.Web/certificates" template takes a pfxblob and a password.
It seems the easiest way of obtaining a pfxblob is via New-AzureRmApplicationGatewaySslCertificate (thanks to #vigneshaj for the pointer) reading the source, it seems that this is simply a local conversation cmdlet. So it doesn't matter that it is for an application gateway, all we need is the data it passes back.
$pfx = New-AzureRmApplicationGatewaySslCertificate -Name example `
-CertificateFile E:\PS\example.pfx `
-Password "bananas"
Once we have that data, we can simply plug it into New-AzureRmResource and it will create our certificate on Azure.
The small problem with this, is that if you're a cheapskate (like me) and you've obtained a free cert from that Chinese CA that gives sha256 certs, this process will strip off the certificate that signs pages with sha256, and so it falls back to TLS 1.2, which gives errors (on Chrome at least)
$ResourceLocation = "West Europe"
$ResourceName = "Newcertificate"
$PropertiesObject = #{
pfxBlob = $pfx.Data
password = $pfx.Password
}
New-AzureRmResource -Name $ResourceName -Location $ResourceLocation `
-PropertyObject $PropertiesObject `
-ResourceGroupName examplecomRG `
-ResourceType Microsoft.Web/certificates `
-ApiVersion 2015-08-01 -Force
The next job from there is configuring your Web App to use that cert. Because these properties are child objects of the hostNameSslStates array I created an inner hash table, and then attached that. I'm sure there's a more elegant way, but this worked!
$ResourceName = "ConfuseioWebapp"
$InnerPropertiesObject = #{
name = "www.example.com"
sslState = 1
thumbprint = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
}
$PropertiesObject = #{
"hostNameSslStates" = [Object[]]$InnerPropertiesObject
}
New-AzureRmResource -Name $ResourceName `
-Location $ResourceLocation `
-PropertyObject $PropertiesObject `
-ResourceGroupName examplecomRG `
-ResourceType Microsoft.Web/sites `
-ApiVersion 2015-08-01 -Force
And that is pretty much it.
I came across the below article, which configures SSL through powershell, by creating Azure Application Gateway
https://azure.microsoft.com/en-us/documentation/articles/application-gateway-ssl/