1

我试图获取所有已部署的 Azure 云服务,特别是寻找服务名称及其标签字段。我正在使用 cmdlet Get-AzureDeployment,但它没有返回所需的结果。

使用的 cmdlet: $getResultForMyService = Get-AzureDeployment -ServiceName "myservicelistedincloudservice" -Slot "Production"

我得到的输出是

  *>Get-AzureDeployment : ResourceNotFound: No deployments were found.
  OperationID : 'a********************074'
    At line:1 char:9
+ $Data = Get-AzureDeployment -ServiceName myservicelistedincloudservice" -Slot "Prod …
+ CategoryInfo : CloseError: (:) [Get-AzureDeployment], ComputeCloudException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.GetAzureDeploymentCommand*

在运行 Get-AzureDeployment cmdlet 之前,我尝试确保上下文使用了正确的订阅。但这也没有帮助。

PS C:\WINDOWS\system32> set-azurermcontext -SubscriptionName MySubscription

仅供参考,我已经安装了最新版本,并且在执行上述 cmdlet 之前,我还导入了 Azure 模块。仅供参考,以下是我的 PS 版本详细信息:

我还按照 MS 文档链接中的服务管理模块的安装说明进行操作,但这也无济于事 - https://docs.microsoft.com/en-us/powershell/azure/servicemanagement/install-azure-ps?view=azuresmps -4.0.0

PS C:\WINDOWS\system32> $psversiontable

名称 值
---- -----
PSVersion 5.1.17763.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1 CLRVersion
4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

任何列出云服务的指针将不胜感激。

4

1 回答 1

2

终于得到了这个工作。我点击了这个链接https://social.msdn.microsoft.com/Forums/en-US/77d36a5e-9c98-4003-bc52-367c00156b40/how-to-change-subscription?forum=azurescripting

由于此 Get-AzureDeployment cmdlet 与 ASM 有关,因此我使用了非 rm cmdlet,以下是我遵循的 cmdlet 和步骤:

步骤 1: 添加 AzureAccount

最初我收到此错误“没有订阅与 Azure 服务管理 (RDFE) 中的登录帐户相关联。” 我在将自己添加到共同管理员角色后摆脱了这个问题,即使我在 Portal 中为我的订阅拥有所有者角色。

步骤 2: 获取 AzureSubscription

这应该列出所有订阅,并说明哪一个是默认(IsDefault)和当前(IsCurrent)订阅。请注意 IsCurrent = True 或 IsDefault = True 的订阅。请注意,这两个参数已弃用,并且对于任何订阅都将具有相同的值,换句话说,您不能将一个订阅设置为 IsCurrent = True,而将另一个订阅设置为 IsDefault = True。

第三步: 选择-AzureSubscription -SubscriptionName mysubscription

如果您的 mysubscription 是当前订阅 (IsCurrent = True),则不需要此 cmdlet,否则运行此 cmdlet 以将 mysubscription 设置为您的当前订阅。

第 4 步: Get-AzureDeployment -ServiceName "myservicelistedincloudservice" -Slot "Production"

如果此服务(myservicelistedincloudservice)属于 mysubscription 订阅,那么这将返回结果,因为它已设置 IsCurrent = True,否则您将看到“ResourceNotFound:未找到部署”。错误。

我们需要确保 4 个 cmdlet 以与上述相同的顺序执行,否则您将不知道导致问题的原因。希望这会对某人有所帮助。

于 2018-11-10T09:18:27.030 回答