Azure's New-AzureRmHDInsightCluster command does not accept documented ComponentVersion option - azure

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.

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.

Unable to scale Azure SQL database using a variable

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.

Runbook can't use command New-AzureRmSqlDatabaseExport (Object reference not set to an instance of an object)

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

creating vm and running installation script in azure

I'm looking for a way to run a script that creates a simple windows vm with rdp port and installs a software on it in order give our clients a simple sand boxed server for testing purposes. Is there a simple way to do that as I've been struggling for a while now.
You should use custom script extension for Azure VM. Depending on how you create vms you can use powershell\cli\arm templates\rest api\sdk to use that extension.
sample powershell:
$ProtectedSettings = #{"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File \\filesvr\build\serverUpdate1.ps1"};
Set-AzureRmVMExtension -ResourceGroupName myRG
-Location myLocation `
-VMName myVM `
-Name "serverUpdate"
-Publisher "Microsoft.Compute" `
-ExtensionType "CustomScriptExtension" `
-TypeHandlerVersion "1.9" `
-ProtectedSettings $ProtectedSettings
ARM Template sample: https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-custom-script-windows
AZ cli sample: https://blogs.technet.microsoft.com/paulomarques/2017/02/13/executing-custom-script-extension-using-azure-cli-2-0-on-an-azure-linux-virtual-machine/

Resources