View or export automation account modules

Ryan Shaw 1 Reputation point
2022-01-05T10:53:43.537+00:00

Is there a way to read/view or even export the code within a custom module created within an Azure automation account. I've inherited this account and it's runbooks, and there's a custom module being used that I don't have the source code for. I'd like to peak under the hood but I can't see a way to access the existing codebase.

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

3 answers

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,386 Reputation points
    2022-01-07T09:12:10.84+00:00

    Hi @Ryan Shaw

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Option to Export custom module is not readily available in Azure Automation account. I am reaching out to my team and will update this thread in case there is an alternate way.

    ---
    Edit: 01/12/2022

    To get the custom modules uploaded to Azure Automation account, you can create a support ticket and we can help get it from backend.

    Please let me know if you have any questions.

    ---
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

  2. Ryan Shaw 1 Reputation point
    2022-01-13T22:27:43.993+00:00

    Microsoft support helped me create a script that saves the Module to a container.

    1. Create the container within the Storage Account first
    2. Then create a Runbook within the Automation Account
    3. Fill in the variables at the top of this script and run
         $ModulesRequired = @("Enter the module names you need to retrieve")
      $StorageAccountName = "Enter the storage account name"
      $StorageAccountKey = "Enter the storage account Access Key"
      $ContainerName = "Enter an existing container for the storage account"
      
      $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
      
      "Searching for modules: $($ModulesRequired -join '|')"
      $Modules = Get-ChildItem -Path "C:\Modules\User" | ?{$_.Attributes -eq "Directory"} | where Name -match $($ModulesRequired -join '|') 
      
      Foreach($Module in $Modules)
      {
          $ModuleName = $Module.Name
          "Retrieving files from module: $ModuleName to save to container: $ContainerName"
          $files = Get-ChildItem -Path "C:\Modules\User\$ModuleName"
      
          Foreach($File in $Files)
          {
               Set-AzureStorageBlobContent -File $File.FullName -Container $ContainerName -Blob $($ModuleName + "\" + $File.name) -Context $Context | Out-Null
               "File saved: $($File.Fullname)" 
          }
      }
      "Done"
      

  3. Ryan Coplien 0 Reputation points
    2024-05-02T14:22:08.4533333+00:00

    Due to infrastructure changes with Azure runbooks, I have created an updated script based on the original output from @Ryan Shaw

    This was specifically made with exporting custom modules in mind.

    $ModulesRequired = @("Enter the module names you need to retrieve")
    $StorageAccountName = "Enter the storage account name"
    $StorageAccountKey = "Enter the storage account Access Key"
    $ContainerName = "Enter an existing container for the storage account"
    
    $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
    
    "Searching for modules: $($ModulesRequired -join '|')"
    $Modules = Get-ChildItem -Path "C:\usr\src\PSModules" | ?{$_.Attributes -eq "Directory"} | where Name -match $($ModulesRequired -join '|') 
    
    Foreach($Module in $Modules)
    {
        $ModuleName = $Module.Name
        "Retrieving files from module: $ModuleName to save to container: $ContainerName"
        $files = Get-ChildItem -Path "C:\usr\src\PSModules\$ModuleName"
    
        Foreach($File in $Files)
        {
             Set-AzureStorageBlobContent -File $File.FullName -Container $ContainerName -Blob $($ModuleName + "\" + $File.name) -Context $Context | Out-Null
             "File saved: $($File.Fullname)" 
        }
    }
    "Done"
    
    0 comments No comments

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.