0
votes

In the Windows Azure portal, from my automation accounts (Automation accounts > myAutomation > Runbooks > MyRunbook > Edit PowerShell workflow Runbook > Test), I'm trying to test a powershell script with the Azure Resource Manager library, for migrations purposes. I wrote a small piece of a powershell script and tested it in the test pane. I'm facing an error message:

The term 'New-AzureRmHDInsightHiveJobDefinition' 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.

I want to test it directly from the Windows Azure Portal because I need to use some result of function like "Get-AutomationPSCredential".

PowerShell script sample

workflow Runbook_Test
{
    param(            
        [parameter(Mandatory=$True)]
        [string] $HDInsightAdminCredendialsName
    )

    $hdInsightCredentials = Get-AutomationPSCredential -Name $HDInsightAdminCredendialsName
    InlineScript {
        $creds = $using:hdInsightCredentials
        $clusterName = 'clusterName'            

        $query = 'A QUERY INSIDE'

        $jobDef = New-AzureRmHDInsightHiveJobDefinition -Query $query;
        $hiveJob = Start-AzureRmHDInsightJob -JobDefinition $jobDef -ClusterName $clusterName -HttpCredential $creds 
        Wait-AzureRmHDInsightJob -JobId $hiveJob.JobId -ClusterName $clusterName -HttpCredential $creds 
    }    
}

I have the same issue with cmdlet "Start-AzureRmHDInsightJob" and "Wait-AzureRmHDInsightJob". It's like azure portal don't recognize the ARM library.

For sure I'm miss something, but what? :) Thanks for your help.

2

2 Answers

1
votes

You need to import those modules into your Azure Automation Account. In this case you need AzureRM​.HDInsight module. Consult this link on how to import modules: https://docs.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery

The thing is, your account only gets some of the Azure Powershell modules by default, the rest you have to install manually.

1
votes

The issue what I am understanding is because of the workflow scopes.

I would recommend you to use a function instead of workflow and try it once. So that you can segregate the issue that it is a Library issue or Scope.

If the issue is with the scope and you want to use workflow then we have make use of passing parameters inside each scope of workflow. So that the ARM library can understand the cmdlets "Start-AzureRmHDInsightJob" and "Wait-AzureRmHDInsightJob" inside the scope.

For your answer, Azure cmdlets are working properly in mine if using function and global variables.