skip to Main Content

I’m trying to automate the sentinel alerts. It requires Az.Accounts and Az.securityInsights modules as pre-requisites. I’m running PowerShell scripts via automation account.

The PowerShell runbook contains default versions of Az.Accounts and Az.SecurityInsights modules. I need to update these modules to the latest version for PowerShell 5.1 version.

I have used the below command but facing error:

Get-InstalledModule -Name Az.Accounts | Update-Module

Error:

System.Management.Automation.MethodInvocationException: Exception calling "ShouldContinue" with "2" argument(s): "A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGet provider must be available in ‘C:Program FilesPackageManagementProviderAssemblies’ or ‘C:UsersClientAppDataRoamingPackageManagementProviderAssemblies’. You can also install the NuGet provider by running ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet to install and import the NuGet provider now?"

How can I update the versions of these modules via PowerShell script?

Az.Accounts (>2.11 version)
Az.SecurityInsights (3.0.1 version)

Update

As per suggestions given by answerers, I used this script but still facing below error:

# Install the latest version of the NuGet provider
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force 

# Update the Az.Accounts module
Update-Module -Name Az.Accounts -Force

# Update the Az.SecurityInsights module
 Update-Module -Name Az.SecurityInsights -Force

# Import the updated modules
 Import-Module Az.Accounts
 Import-Module Az.SecurityInsights

Error:

No match was found for the specified search criteria for the provider ‘NuGet’. The package provider requires ‘PackageManagement’ and ‘Provider’ tags. Please check if the specified package has the tags.

2

Answers


  1. Use the ‘-Force’ option:

    Get-InstalledModule -Name Az.Accounts | Update-Module -Force
    

    If that doesn’t work, update the NuGet version then try again:

    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
    
    Login or Signup to reply.
  2. I too received same errors when I tried your command and other answer’s command as below:

    enter image description here

    enter image description here

    To update modules try to follow below steps and I followed Microsoft-Document:

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    Another way of doing that is:

    enter image description here

    By following below steps you can update your packages in Runbook. AFAIK, using commands you will get errors as have got. So I suggest you to try to follow traditional and documented way like above process.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search