我想导出所有存储帐户,在输出中显示其Sku.Name,但调用它时遇到问题



到目前为止,以下是我所拥有的:

$result=@()
$storageaccounts= Get-AzStorageAccount
foreach($storageaccount in $storageaccounts){

$obj = [PSCustomObject]@{
$Name= $storageaccount.ResourceGroupName
$Location= $storageaccount.Location
$Kind= $storageaccount.Kind
$Replication= $storageaccount.sku.Name
}
$result += $obj
} 
$result | Export-Csv -Path "insert path" 

您只是使用未定义的变量创建对象。

此外,我认为属性是SkuName而不是Sku.Name

当您不确定对象具有什么属性时,可以使用Get-Member:

$storageaccounts = Get-AzStorageAccount
$storageaccounts | Get-Member
$storageaccounts = Get-AzStorageAccount
$result = foreach($storageaccount in $storageaccounts)
{
[PSCustomObject]@{
Name = $storageaccount.ResourceGroupName
Location = $storageaccount.Location
Kind = $storageaccount.Kind
Replication = $storageaccount.SkuName
}
}
$result | Export-Csv -Path "insert path"

相关内容

最新更新