我想导出所有存储帐户,在输出中显示其 Sku.Name,但调用它时遇到问题
I want to get an export of all storage accounts, where in the output it shows its Sku.Name, but am having trouble calling it
以下是我目前的情况:
$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"
以下是我目前的情况:
$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"