Giter VIP home page Giter VIP logo

azureautomation-account-modules-update's Introduction

Updating Azure PowerShell modules in Azure Automation accounts

Build Status

Purpose

This Azure Automation runbook updates Azure PowerShell modules imported into an Azure Automation account with the module versions published to the PowerShell Gallery. See How to update Azure PowerShell modules in Azure Automation for more details.

Usage

Import this runbook into your Automation account, and start it as a regular Automation runbook.

Notes

  • If you import this runbook with the original name (Update-AutomationAzureModulesForAccount), it will override the internal runbook with this name. As a result, the imported runbook will run when the Update Azure Modules button is pushed or when this runbook is invoked directly via ARM API for this Automation account. If this is not what you want, specify a different name when importing this runbook.
  • Azure and AzureRM.* modules are currently supported by default.
  • The new Azure PowerShell Az modules are also supported. You must supply the AzureModuleClass runbook parameter with Az if your runbooks use only Az modules to avoid conflicts. More information can be found in the Microsoft Docs and issue #5.
  • Before starting this runbook, make sure your Automation account has a System assigned Managed Identity created.
  • You can use this code as a regular PowerShell script instead of a runbook: just login to Azure using the Connect-AzureRmAccount command first, then pass -Login $false to the script.
  • To use this runbook on the sovereign clouds, provide the appropriate value to the AzureEnvironment parameter. Please also make sure you read the compatibility notes.
  • When facing compatibility issues, you may want to use specific older module versions instead of the latest available on the PowerShell Gallery. In this case, provide the required versions in the ModuleVersionOverrides parameter.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azureautomation-account-modules-update's People

Contributors

anatolib avatar awsles avatar ayoung012 avatar d1v38om83r avatar krmanupa avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar superfliege avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azureautomation-account-modules-update's Issues

Syntax errors after importing as PS1

I imported this to my Azure Automation Resource Group but get synatax errors when I run it I get a lot of these syntax errors

Failed
At line:165 char:21
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

And
~
The '<' operator is reserved for future use.

Unable to import module in Automation account

After I add the module inside the Azure automation account, it says importing for a few minutes and fails with this error.

Error importing the module AzureAutomation-Account-Modules-Update-master. Import failed with the following error: Orchestrator.Shared.AsyncModuleImport.ModuleImportException: Cannot import the module of name AzureAutomation-Account-Modules-Update-master, as the module structure was invalid.

Please check.

404 Error when updating "AzureRM.Subscription 0.2.1-preview" module

Scenario

When trying to update an Automation Account containing the AzureRM.Subscription 0.2.1-preview Module, the Runbook falls into an infinite loop with the following error:

The remote server returned an error: (404) Not Found.

This error appears to repeated indefinitely.

Log Stream

The following snippet shows the log entries relating to this with Verbose logging enabled:

VERBOSE: GET https://www.powershellgallery.com/api/v2/package/AzureRM.Subscription with 0-byte payload
ERROR: Invoke-WebRequest : 
 
 PowerShell Gallery
 | Page Not Found
  
 // Application Insights usage
 var appInsights = window.appInsights || function(config) {
 function s(config) {
 t[config] = function() {
 var i = arguments;
 t.queue.push(function() { t[config].apply(t, i) })
 }
 }
 var t = { config: config }, r = document, f = window, e = "script", o = r.createElement(e), i, u;
 for (o.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", 
 r.getElementsByTagName(e)[0].parentNode.appendChild(o), t.cookie = r.cookie, t.queue = [], i = ["Event", "Exception", 
 "Metric", "PageView", "Trace"]; i.length;) s("track" + i.pop());
 return config.disableExceptionTracking || (i = "onerror", s("_" + i), u = f[i], f[i] = function(config, 
 r, f, e, o) {
 var s = u && u(config, r, f, e, o);
 return s !== !0 && t["_" + i](config, r, f, e, o), s
 }), t
 }({
 instrumentationKey: "50d4abc3-17d3-4a1b-8361-2d1e9ca8f6d5"
 });
 
 window.appInsights = appInsights;
 appInsights.trackPageView(); 
 
 Register / Sign in
  
 Home
 Packages
 Publish
 Statistics
 Documentation
 Status
 
 Oops!
 Error 404 - Page Not Found
 
Looks like you might have gotten lost. Let's see if we can help you find your way!
 Get me out of here! Go home
 Wondering if PowerShell Gallery is down? Check our status
 Looking for a package? Try searching
 Package you're looking for doesn't exist? Make one
 Pretty sure we messed up? File a bug
 Contact Us
 Terms of Use
 Privacy Policy
 &copy; 2019 Microsoft Corporation

 At line:178 char:30
 + ... ntentUrl = (Invoke-WebRequest -Uri $ModuleContentUrl -MaximumRedirect ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], 
 WebException
 + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Problem Areas

There appear to be two problematic areas in regards to this.

  1. The script is trying to download a page which doesn't appear to exist for preview modules.
  2. The script gets stuck in an infinite loop due to the lack of error handling in Function "Import-AutomationModule"

The following is the code snippet where this error is occurring:

    # Find the actual blob storage location of the module
    do {
        $ModuleContentUrl = (Invoke-WebRequest -Uri $ModuleContentUrl -MaximumRedirection 0 -UseBasicParsing -ErrorAction Ignore).Headers.Location 
    } while (!$ModuleContentUrl.Contains(".nupkg"))

Resolution

To resolve this, I believe you need to firstly identify when a module is in preview and handle this request differently. You then also need to add correct error handling to cope with transitive vs. more permanent errors when connecting to the PowerShell gallery.

It would be good to see use of an exponential backoff as part of your Retry pattern and introduction of the Circuit Breaker pattern to handle the different error types to ensure the script shuts down gracefully.

Question about update Az Module related to #5

I have an automation account I am going to only use Az module. From Azure doc https://docs.microsoft.com/en-us/azure/automation/az-modules, AzureRM modules are still installed when create automation account and there is no way to remove the AzureRM modules. The doc says "When a new Automation Account is created the existing AzureRM modules will still be installed and the tutorial runbooks will still be authored with AzureRM cmdlets." This means both AzureRM and Az modules are installed for my automation account. The ReadMe of this "Update-AutomationAzureModulesForAccount" says "Avoid starting this runbook on Automation accounts that contain both AzureRM and Az modules."

I am confused. My question is, can this runbook be used to update Az Modules on the automation account? Because every automation account will have AzureRM modules installed by default. I haven't found an option to remove AzureRM modules (the delete button is not available).
Thanks for your help in advance.

Update fails when PS gallery REST request returns nothing

Runbook failing with error below

Cannot index into a null array. At line:216 char:5
 + $LatestModuleVersionOnGallery = (Get-ModuleDependencyAndLatestVer ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Unable to execute no module for AzureRM.Profile

I am executing Update-AutomationAzureModulesForAccount.ps1 in azure automation. The package returns error messages:
PackageManagement\Get-Package : No match was found for the specified search criteria and module names 'AzureRM.Profile'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2253 char:9

  •     PackageManagement\Get-Package @PSBoundParameters | Microsoft. ...
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
    • FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
      and
      Get-AzureRmAutomationModule : The module was not found. Module name: AzureRM.Profile.
      At line:383 char:33
  •         $AutomationModule = & $GetAutomationModule `
    
  •                             ~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [Get-AzureRmAutomationModule], ResourceNotFoundException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationModule

Automation Job failed to perform update

I imported the ps1 script into the Automation Account as a new job. I ran the job and it threw an exception:

Cannot bind parameter 'Environment'. Cannot convert the "AzureCloud" value of type "System.String" to type "Microsoft.Azure.Common.Authentication.Models.AzureEnvironment". (Cannot convert the "AzureCloud" value of type "System.String" to type "Microsoft.Azure.Common.Authentication.Models.AzureEnvironment".)

The only input was my resource group and automation account name.

The only output was "Logging in to Azure (AzureCloud)..."

So that means it's failing in the Add-AzureRmAccount system call with the -Environment argument not being right. But it should be fine as a string so what is going on here then?

Failure

Getting an error:

Wait-AllModulesImported : Failed to import module : AzureRM.Automation. Status : Failed At line:423 char:17 + ... Wait-AllModulesImported -ModuleList $ModuleList -Count $i ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Wait-AllModulesImported

Fails/ Loops if Run As Account is broken/ not sufficient permissions

We recently moved a Automation Account to a new subscription, after that the Update Modules runbook (button in Aure Runbook Account \ Modules \ Update Azure Modules) stopped working.
The runbook would loop for ever, throwing houndreds of error messages like these:

The module was not found. Module name: AzureRM.Profile.

Request:

  • Make the runbook sense whether it has sufficient permissions on the subscription it's working against, stop the runbook and throw a meaningfull error message that tells the user why it failed.

I eventually found about the broken Run As Account thanks to Microsoft Azure Support. In the future you could probably make support requests like this a thing of the past.

update azure runbooks - failes loops

Page not found error

Hello,

I get a Page not found(500) error for all the files i want to access.

Can you please advise?

Thanks
Sampath

I cannot get the update to run with Environment parameter on Add-AzureRmAccount

The error I get is:

Cannot bind parameter 'Environment'. Cannot convert the "AzureCloud" value of type "System.String" to type "Microsoft.Azure.Common.Authentication.Models.AzureEnvironment". (Cannot convert the "AzureCloud" value of type "System.String" to type "Microsoft.Azure.Common.Authentication.Models.AzureEnvironment".)

if I remove this line it works

Escape Reserved Operators | PowerShell Runbook

Runbook test panel ERROR:

Failed

At line:173 char:192

  • ... a-ga-click='"(Logged out) Header, go to Features"'>Features <span cla ...

Example of corrections:
<a href="/features" class="py-2 lh-condensed-ultra d-block link-gray-dark no-underline h5 Bump-link--hover" data-ga-click='"(Logged out) Header, go to Features">Features <span class="Bump-link-symbol float-right text-normal text-gray-light">&rarr;'</span></a>

Clean up script analyzer warnings for Update-AutomationAzureModulesForAccount

When checking the Update-AutomationAzureModulesForAccount.ps1 runbook with ScriptAnalyzer, the following warnings are generated.

WARNING: Update-AzureAutomationModulesForAccount.ps1 (Line 166): 'Add-AzureRmAccount' is an alias of 'Connect-AzureRmAccount'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.

WARNING: Update-AzureAutomationModulesForAccount.ps1 (Line 173): 'Select-AzureRmSubscription' is an alias of 'Set-AzureRmContext'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.

When try to upgrade 'Az' modules, encounter an error "Object reference not set to an instance of an object."

image
Detailed errors:
Get-AzAutomationModule : Object reference not set to an instance of an object. At line:314 char:36 + $CurrentAutomationModuleList = & $GetAutomationModule ` + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzAutomationModule], NullReferenceException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationModule

image

image

This issue has been reproduced in global azure. Please help have a check. Great appreciation!

Never ran...

This never even started for me in Azure Government. Job showed as failed but no useful information

Unable to update Modules

Trying to update the Automation Account modules but it fails with :
Add-AzureRmAccount : Invalid provider type specified. At line:123 char:13 + Add-AzureRmAccount ` + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Connect-AzureRmAccount], CryptographicException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

Unable to import VirtualDesktop into Automation Account via the portal

I have created a new Automation Account (via the Portal) and have select Modules -> Browse Gallery and searched for VirtualDesktop

I selected Virtual Desktop module version 1.1.0 and clicked Import

After a minute of importing, the following error appears. Any suggestions for what I can do? I'm sure this worked a few weeks ago:

Error importing the module VirtualDesktop. Import failed with the following error: Orchestrator.Shared.AsyncModuleImport.ModuleImportException: An error occurred during module validation. When importing the module to an internal PowerShell session, it was not able to be loaded by PowerShell. There is likely an issue with the contents of the module that results in PowerShell's not being able to load it. Please verify that the module imports successfully in a local PowerShell session, correct any issues, and then try importing again.

Module not updating due to dependant module too recent

Hello,

I am trying to update my Automation Account modules with this script.
It is working well for some modules with few dependencies but for other it is not working (especially with modules with lots of dependencies).

For exemple, the Az module can't be updated by the script because the last Azure.Batch module version is 3.2.1 (updated by the script) but the required version for the Az module must be equal to 3.2.0. (There is the same problem with other dependant modules when updating Az)

Screen of the dependencies needed for Az :
image

Screen of the Az.Batch module version in my automation account :
image

Here is the error when the script tries to update the Az module :
image

Is there anything I can do to avoid this problem ?
Is this issue known and being solved ?

Thanks for reading and helping me

Add parameter to allow importing a module array

When using this script to update Az modules in Azure China cloud, it will only import Az.Accounts module. It is inconvenient for customer because if they want other Az modules, they cannot import the modules with this script.

Is it possible to by default import Az.Compute and Az.Storage modules?
Or optionally provide a parameter to allow users to import modules from a module array.

How to create a specific work item (Bug) for each failed test case in Azure DevOps pipelines

Its not an Issue but need help for the problem

I'm using VS Test task for automated testing as part of my release pipeline in Azure DevOps. In build pipeline, there is option to create a bug if whole build fails as part of definition. I do not see that in release definition.

But i'm curious to find, if i have 5 test cases in a test suite and 2 test cases got failed and 3 test cases got passed. So is there any way to create a work item (bug) for only each of the failed test cases as part of release pipeline.

Please suggest me if that option is available.

RunAs Account should not be required.

In accordance with our mandated governance standards we do not create Run As accounts for automation accounts. We do not want to grant a Run As account contributor access to a subscription. Please note in Microsoft's documentation "Note that the creation of Run As accounts may affect the security of the subscription". We DO NOT want to have to run this with a Run As account because it will violate our security policies. We HAVE to get Az.Accounts updated to 2.2.8. This is preventing work from moving forward.

Microsoft provided this Automation service and removed the UX capability to update modules. This update script is absolutely terrible. We need to be able to update our modules and cannot. The documentation on this whole process is sparse and poorly written. Are we expected to add credentials to the code you wrote in order to simply update our modules in Azure automation? Then why are you even providing this service? Its easy to setup a similar infrastructure on premise yet here we are paying for a broken service....again.

Running the update module via a runbook this is what is returned

Failed
Connection 'AzureRunAsConnection' not found. (Connection 'AzureRunAsConnection' not found.)

RunAsAccount not found. To create this RunAsAccount, navigate to the RunAsAccount blade and create a RunAsAccount. Refer doc for more details (https://docs.microsoft.com/azure/automation/create-runas-account)
Logging in to Azure (AzureCloud)...
Connection 'AzureRunAsConnection' is incompatible type.

Update script stopped working alltogether -> get_SerializationSettings' ...

Failed
Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. (Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.