英文:
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
我尝试了您的命令以及其他答案中提到的命令,也遇到了相同的错误,如下所示:
尝试更新模块,请按照以下步骤操作,并且我遵循了Microsoft文档:
另一种方法是:
按照以下步骤,您可以在Runbook中更新您的包。据我所知,使用命令会出现错误,就像我遇到的那样。所以我建议您尝试按照上述过程,采用传统和已记录的方式进行操作。
英文:
I too received same errors when I tried your command and other answer's command as below:
To update modules try to follow below steps and I followed Microsoft-Document:
Another way of doing that is:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论