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

时间:2020-07-20 22:25:11

标签: powershell cmdlet

我正在尝试运行powerhsell脚本(my_script)。该脚本存储在桌面上的this_folder中。我正在使用C:\Users\me\desktop\this_folder> .\my_script在正确的路径上执行命令。当我尝试执行此操作时,我得到了错误

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

我知道Add-AzureRmAccountAzureRM.Profile模块的一部分。进入modules文件夹后,我看到列出了AzureRM.Profile。为了获得这些模块,我运行了Install-Module -name AzureRMImport-module AzureRM

有什么想法吗?

-更新- 当我运行Get-Module命令时,我看到仅列出了AzureRM模块。我试图运行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

由于我看到AzureRM.Profile列出的路径之一中带有nupkg的{​​{1}}文件夹,我以为我可以运行$env:PSModulePath并得到错误消息

Import-Module -Name AzureRM.Profile

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您说已经安装并导入了AzureRM模块,但是是否已将Azure帐户与Connect-AzureRmAccount cmdlet连接起来? 我知道,在与帐户/订阅建立有效连接之前,许多其他模块不会公开所有可用的cmdlet。

请注意,脚本可以忽略运行脚本的上下文,因此您可能需要在脚本的开头添加以下内容:

Import-Module AzureRM
Connect-AzureRmAccount 

而不是在控制台中手动运行它们,然后运行脚本。

您可能还想看看使用Az模块来代替,因为AzureRM模块将被淘汰,并且仅会得到bug修复,直到2020年12月结束:Introducing the new Azure PowerShell Az module