首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么VScode pwsh终端不能看到我的azure资源组?

为什么VScode pwsh终端不能看到我的azure资源组?
EN

Stack Overflow用户
提问于 2019-07-12 15:54:47
回答 1查看 151关注 0票数 0

我正在尝试使用CSV文件中的标签来标记所有来自azure的运行中的虚拟机,但我的PowerShell脚本在从VSCode PowerShell核心终端运行时失败。

我仔细检查了一下,并设置了正确的活动订阅(我们有多个租户和订阅),但输出结果显示它找不到我的资源组(它们肯定在那里)。

代码语言:javascript
复制
Enable-AzureRmAlias
$csv = import-csv "C:\Users\popes\Desktop\Jedox\Powershell scripts\Tagging\Tagging.csv"

$csv | ForEach-Object {
    # Retrieve existing tags
    $tags = (Get-AzResource -ResourceGroupName $_.RG -ResourceType "Microsoft.Compute/virtualMachines" -Name $_.VM).Tags

    # Define new value pairs from CSV
    $newTags = @{
        company     = $_.Company
        dns         = $_.DNS
        type        = $_.Type
        CN          = $_.CN
    }

    # Add new tags to existing set (overwrite conflicting tag names)
    foreach($CN in $newTags.Keys){
        $tags[$_] = $newTags[$_]
    }

    # Update resource with new tag set
    Set-AzResource  -ResourceGroupName $_.RG -Name $_.VM -Tag $tags -ResourceType "Microsoft.Compute/virtualMachines"
}

输出:

代码语言:javascript
复制
Get-AzResource : Resource group 'machine774_rg' could not be found.
At line:3 char:14
+ ...    $tags = (Get-AzResource -ResourceGroupName $_.RG -ResourceType "Mi ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Get-AzResource], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet

Cannot index into a null array.
At line:15 char:9
+         $tags[$_] = $newTags[$_]
+         ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-15 14:14:05

尝试使用Clear-AzContext,然后使用特定的租户和订阅Connect-AzAccount -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy"登录。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57002542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档