如何通过PowerShell运行簿更新PowerShell模块?

huangapple go评论57阅读模式
英文:

How to update PowerShell modules via PowerShell runbook?

问题

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 Files\PackageManagement\ProviderAssemblies' or 'C:\Users\Client\AppData\Roaming\PackageManagement\ProviderAssemblies'. 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.

英文:

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 Files\PackageManagement\ProviderAssemblies' or 'C:\Users\Client\AppData\Roaming\PackageManagement\ProviderAssemblies'. 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.

答案1

得分: 0

使用"-Force"选项:

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

如果这不起作用,更新NuGet版本然后再次尝试:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
英文:

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

答案2

得分: 0

我尝试了您的命令以及其他答案中提到的命令,也遇到了相同的错误,如下所示:

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

尝试更新模块,请按照以下步骤操作,并且我遵循了Microsoft文档

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

另一种方法是:

如何通过PowerShell运行簿更新PowerShell模块?

按照以下步骤,您可以在Runbook中更新您的包。据我所知,使用命令会出现错误,就像我遇到的那样。所以我建议您尝试按照上述过程,采用传统和已记录的方式进行操作。

英文:

I too received same errors when I tried your command and other answer's command as below:

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

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

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

如何通过PowerShell运行簿更新PowerShell模块?

Another way of doing that is:

如何通过PowerShell运行簿更新PowerShell模块?

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.

huangapple
  • 本文由 发表于 2023年3月12日 15:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711631.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定