简体   繁体   English

尽管安装了正确的模块,但无法识别 Powershell cmdlet

[英]Powershell cmdlet is not recognized despite having the correct module installed

I am trying to run a powerhsell script (my_script).我正在尝试运行 powerhsell 脚本(my_script)。 The script is stored in this_folder on the desktop.脚本存储在桌面的this_folder中。 I am executing the command at the the correct path by using C:\Users\me\desktop\this_folder>.\my_script .我正在使用C:\Users\me\desktop\this_folder>.\my_script在正确的路径执行命令。 When I try to do this I get the error当我尝试这样做时,我得到了错误

The term 'Add-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again

I know that the Add-AzureRmAccount is a part of the AzureRM.Profile module.我知道Add-AzureRmAccountAzureRM.Profile模块的一部分。 When I got to the modules folder, I see that AzureRM.Profile is listed.当我进入模块文件夹时,我看到AzureRM.Profile已列出。 To get these modules, I ran Install-Module -name AzureRM and Import-module AzureRM .为了获得这些模块,我运行了Install-Module -name AzureRMImport-module AzureRM

Any ideas what might be going on?任何想法可能会发生什么?

---Update--- When I ran Get-Module commands I saw that only that AzureRM module was listed. ---更新---当我运行Get-Module命令时,我看到只列出了那个 AzureRM 模块。 I thne tried to run Install-Module -Name AzureRM.Profile and got the error:我试图运行Install-Module -Name AzureRM.Profile并得到错误:

At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters

Since I see the AzureRM.Profile folder with a nupkg at one of the paths listed by $env:PSModulePath I thought I could just run Import-Module -Name AzureRM.Profile and I get the error因为我在$env:PSModulePath列出的路径之一看到带有nupkgAzureRM.Profile文件夹,所以我想我可以运行Import-Module -Name AzureRM.Profile并收到错误

import-module : The specified module 'AzureRM.Profile' was not 
loaded because no valid module file was found in any module directory.

Any ideas?有任何想法吗?

You say that you've installed and imported the AzureRM module, but have you connected the Azure account with the Connect-AzureRmAccount cmdlet?您说您已经安装并导入了 AzureRM 模块,但是您是否已将 Azure 帐户与Connect-AzureRmAccount cmdlet 连接起来? I know a number of other modules does not expose all of the available cmdlets until there is an active connection to an account/subscription.我知道在与帐户/订阅建立活动连接之前,许多其他模块不会公开所有可用的 cmdlet。

Be aware that scripts can ignore the context in which they are run so you might need to add the following to the start of the script:请注意,脚本可以忽略运行它们的上下文,因此您可能需要将以下内容添加到脚本的开头:

Import-Module AzureRM
Connect-AzureRmAccount 

Rather than running them manually in the console and then running the script.而不是在控制台中手动运行它们然后运行脚本。

You might want also want to look at using the Az module instead as the AzureRM module is being retired, and will only get bug-fixes till the end of December 2020: Introducing the new Azure PowerShell Az module您可能还想考虑使用 Az 模块,因为 AzureRM 模块即将退役,并且只会在 2020 年 12 月之前得到错误修复: 介绍新的 Azure PowerShell Az 模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM