New-AzStorageContext' and Get-AzStorageBlobContent are not recognized in a Runbook(powershell) using Hybrid Worker group

2021-01-10T14:37:38.903+00:00

Hi,

How to resolve the below issue?
In Azure portal, Runbook(powershell) is run. But it fails as like below:

Error converting file path The term 'New-AzStorageContext' 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.

Get-AzStorageBlobContent -ErrorAction stop -Blob $fileName -Container $Container -Destination $localFilePath -ClientTimeoutPerRequest 600 -Context $ctx
New-AzStorageContext -ErrorAction stop -storageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

Whereas it runs fine when using, New-AzureStorageContext' and Get-AzureStorageBlobContent

Thanks,
Madhura

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,240 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,451 Reputation points
    2021-01-11T17:06:29.633+00:00

    Hi @SHIVAKUMAR Madhurashree K (Madhura)

    Thanks for your offline time.
    As discussed, we have installed the Az cmdlets on the hybrid worker and found the configuration issue. The machine was logged in with User A credentials and Runbook was triggered using User B(who has the required Subscription) credentials with which the Azure portal was logged in.

    After setting in Azure Portal, Hybrid Workers group settings to use User A (with which machine is logged In), resolved the issue.

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 109.4K Reputation points MVP
    2021-01-10T16:02:24.937+00:00

    If you expand CMDLETS in the Editor the Azure.Storage module is visible?

    This Azure Automation PowerShell script works here without any problem.

    55094-azautoazstorage.jpg

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

  2. Andreas Baumgarten 109.4K Reputation points MVP
    2021-01-10T17:46:07.877+00:00

    Could you please just try a simple PowerShell runbook with just the the New-AzStorageContext line like I did in my script. Keep it please as simple as possible just for testing if the New-AzStorageContext cmdlet is working at all.
    Also please verify you are able to expand the Az.Storagecmdlet on the left side.

    55039-keepitsimple.jpg

    The result should look like this:

    55102-simpleoutput.jpg

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

  3. Andreas Baumgarten 109.4K Reputation points MVP
    2021-01-10T15:11:45.78+00:00

    You imported the Az.Storage module to your Azure Automation Account (not 100% sure if you need the modules AZ.Accounts, AZ.Resource, AZ.Automation as well)?
    https://learn.microsoft.com/en-us/azure/automation/shared-resources/modules

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  4. Andreas Baumgarten 109.4K Reputation points MVP
    2021-01-10T19:06:38.967+00:00

    It doesn't make sense to me but we can give it a try:

    1. Put the cursor in the editor pane where the cmdlet shut show up (in my case line 4)
    2. Expand CMDLETS in the left pane/menu
    3. Expand Az.Storage
    4. Scroll to New-AzStorageContext and expand
    5. Select AccountNameAndKey and click on the ...
    6. Click `Add to canvas``
    7. Modify the lines for your needs

    55103-simple1.jpg

    55018-simple2.jpg

    Give it a try again please ;-) ("fingers crossed" and "drum roll")

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.