【问题标题】:The term 'Select-AzureSubscription' is not recognized as the name of a cmdlet, function术语“Select-AzureSubscription”未被识别为 cmdlet、函数的名称
【发布时间】:2021-05-06 11:16:46
【问题描述】:

我运行以下命令:-

PS C:\WINDOWS\system32> Connect-AzureRmAccount
WARNING: Because the Az modules have all the capabilities of AzureRM modules and more, we will retire the AzureRM
modules on 29 February 2024. Learn more about the migration to Az: http://aka.ms/azpsmigrate.

Account                                 SubscriptionName TenantId                             Environment
-------                                 ---------------- --------                             -----------
**.***@****.onmicrosoft.com                  e***-b4fb-0*** AzureCloud


PS C:\WINDOWS\system32> az login --tenant "c*f"
You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
    "id": "b**4",
    "isDefault": true,
    "name": "Microsoft Azure",
    "state": "Enabled",
    "tenantId": "c**f",
    "user": {
      "name": "***@***.onmicrosoft.com",
      "type": "user"
    }
  }
]
PS C:\WINDOWS\system32> Select-AzureSubscription -Current -SubscriptionId "b**4"
Select-AzureSubscription : The term 'Select-AzureSubscription' 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.
At line:1 char:1
+ Select-AzureSubscription -Current -SubscriptionId "b1597bc1-913e-4da7 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Select-AzureSubscription:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

但是我得到了上述错误任何建议? 谢谢

编辑

我运行这个命令:-

  az login --tenant "c*f"

我得到了这个结果

You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
    "id": "b**4",
    "isDefault": true,
    "name": "Microsoft Azure",
    "state": "Enabled",
    "tenantId": "c**f",
    "user": {
      "name": "***@***.onmicrosoft.com",
      "type": "user"
    }
  }
]

但是当我运行这个命令时:-

Select-AzureRmSubscription -Subscription "b**4"  -Tenant "c**f"

我得到了这个结果

WARNING: Because the Az modules have all the capabilities of AzureRM modules and more, we will retire the AzureRM
modules on 29 February 2024. Learn more about the migration to Az: http://aka.ms/azpsmigrate.
Select-AzureRmSubscription : Please provide a valid tenant or a valid subscription.
At line:1 char:1
+ Select-AzureRmSubscription -Subscription "b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmContext], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand

EDIT-2

我试过这个命令:-

PS C:\WINDOWS\system32> Get-AzureRmSubscription -Subscription "b**4"  -Tenant "c**f"

但我得到了这个错误:-

Get-AzureRmSubscription : Parameter cannot be processed because the parameter name 'Subscription' is ambiguous.
Possible matches include: -SubscriptionId -SubscriptionName.
At line:1 char:25
+ Get-AzureRmSubscription -Subscription "b1597bc1-913e-4da7-a020-be3029 ...
+                         ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmSubscription], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.Azure.Commands.Profile.GetAzureRMSubscriptionCommand

所以我运行这个命令:-

PS C:\WINDOWS\system32> Get-AzureRmSubscription -SubscriptionId "b**4"  -Tenant "c**f"

但是得到了这个错误:-

WARNING: Because the Az modules have all the capabilities of AzureRM modules and more, we will retire the AzureRM
modules on 29 February 2024. Learn more about the migration to Az: http://aka.ms/azpsmigrate.
WARNING: Unable to acquire token for tenant 'cfcab407-f59a-4db4-aec9-d5d3676d708f'
Get-AzureRmSubscription : Subscription b1597bc1-913e-4da7-a020-be30291a6494 was not found in tenant
cfcab407-f59a-4db4-aec9-d5d3676d708f. Please verify that the subscription exists in this tenant.
At line:1 char:1
+ Get-AzureRmSubscription -SubscriptionId "b1597bc1-913e-4da7-a020-be30 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRmSubscription], PSArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.GetAzureRMSubscriptionCommand

【问题讨论】:

  • Select-AzureSubscription 不是 AzureRM 模块的一部分。
  • 不要使用Select-AzureSubscription,请使用Get-AzureRmSubscription
  • 您指定的租户中是否存在订阅?
  • 让我们重新开始:)。您能否更新您的问题并包括您正在运行的最新代码和您获得的输出?此外,请使用租户 ID 和订阅 ID 的前几个字符,而不是“b**4”。谢谢。
  • 啊...我应该早点看到这个。您可以尝试使用Get-AzureRmSubscription 而不是Select-AzureRmSubscription(顺便说一句,我找不到Select-AzureRmSubscription)吗?

标签: azure powershell azure-rm


【解决方案1】:

你可以试试下面的命令行开关:

Select-AzureRmSubscription -Subscription <SUBSCRIPTION> -Tenant <TENANTID>

【讨论】:

  • 我会收到这个错误Select-AzureRmSubscription : Please provide a valid tenant or a valid subscription. At line:1 char:1 + Select-AzureRmSubscription -Subscription "b***8e3 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmContext], ArgumentException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
  • 对不起...给订阅名称Select-AzureRmSubscription -Subscription "&lt;SUBSCRIPTIONNAME&gt;"
  • 你可以运行这个Get-AzureRmSubscription - 获取订阅列表和订阅名称
  • Get-AzureRmSubscription 不会返回任何东西...但是当我运行此命令时az login --tenant "c**f"
  • 你试过Select-AzureRmSubscription -Subscription "Microsoft Azure" 吗?
【解决方案2】:

使用以下命令,因为 -current 不是查询中的正确参数

【讨论】:

  • 我会得到同样的错误PS C:\WINDOWS\system32&gt; Select-AzureSubscription -SubscriptionId b***4 Select-AzureSubscription : The term 'Select-AzureSubscription' 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.
  • 您能否检查一下您的 powershell docs.microsoft.com/en-us/powershell/azure/azurerm/… 中下载的 azure 命令模块,并确保您在管理员模式下运行 powershell
  • Skukla 是的,我正在使用管理员模式运行 + 相关模块已下载
猜你喜欢
  • 2013-08-29
  • 2021-08-19
  • 1970-01-01
  • 2022-08-19
  • 2021-12-22
  • 2019-10-12
  • 2017-12-11
  • 2021-12-09
  • 2020-02-25
相关资源
最近更新 更多