powershell - 访问 ConvertTo-Html cmdlet 中的嵌套属性

标签 powershell azure azure-powershell azure-resource-manager

如何在下面的 html 表格中添加值 Sku.NameSku.Tier

$resourceGroupName = "(my resourcegroup name)"
$storageAccounts = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName
$storageAccounts `
 | ConvertTo-Html `
   -property ResourceGroupName, StorageAccountName, Sku, Sku.Name, Sku.Tier, Kind, Encryption, AccessTier `
   -body "<h2>List of Storage Accounts</h2>" `
   -As List `
 | Set-Content "temp.html"

结果“temp.html”

List of Storage Accounts
ResourceGroupName:  "(my resourcegroup name)"
StorageAccountName: "(my storage account name)"
Sku:    Microsoft.Azure.Management.Storage.Models.Sku
Kind:   BlobStorage
Encryption: Microsoft.Azure.Management.Storage.Models.Encryption
AccessTier: Cool

预期

List of Storage Accounts
ResourceGroupName:  "(my resourcegroup name)"
StorageAccountName: "(my storage account name)"
Sku:    Microsoft.Azure.Management.Storage.Models.Sku
Sku.Name:   StandardLRS
Sku.Tier:   Standard
Kind:   BlobStorage
Encryption: Microsoft.Azure.Management.Storage.Models.Encryption
AccessTier: Cool

错误

尝试

-property (Sku).Name

结果:

+    -property (Sku).Name
+               ~~~
    + CategoryInfo          : ObjectNotFound: (Sku:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

最佳答案

您需要使用计算属性:

-property ResourceGroupName, StorageAccountName, Sku, @{l='Sku Name'; e={$_.Sku.Name}},  @{l='Sku Tier'; e={$_.Sku.Tier}}, Kind, Encryption, AccessTier

关于powershell - 访问 ConvertTo-Html cmdlet 中的嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40461187/

相关文章:

powershell - 新-AzureRmVM : Parameter set cannot be resolved using the specified named parameters

.net - 加载 powershell 脚本大约 10000 次

python - 订阅 Microsoft Office 365 管理事件 API : Authorization denied

azure - 创建 Azure 存储 Blob 容器时出现错误 403(启用存储防火墙

azure - 将 Azure Powershell 命令转换为 Azure CLI

Azure API 将端点重定向到另一个搜索服务

powershell - mkdir 和 mkdir -p 之间的区别?

powershell - 远程注册表项提取器 PowerShell 脚本

windows - PowerShell 从 GitHub API 下载 Zip 文件

azure - Mac Visual Studio 社区的发布/Web 部署