到目前为止,以下是我所拥有的:
$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"