所以我不太精通PowerShell,我不知道如何让它以我想要的方式工作。我试着用谷歌搜索解决方案,但我找不到任何我想要做的事情。我不确定我是不是在寻找正确的东西。不管怎样,我要做的就是展开一个返回的对象。现在,当它只有一个时,它可以很好地工作,但当有多个时,它只输出一个数组。这是针对Veeam Powershell命令的,如果有帮助的话。
有问题的脚本
$clients = @()
foreach($tenant in Get-VBRCloudTenant | Select-Object Name) {
$newTenant = Get-VBRCloudTenant -Name $tenant.Name | Select-Object * -ExcludeProperty SaltedPassword,PasswordSalt
$clients += @{
"LastActive" = $newTenant.LastActive;
"Id" = $newTenant.Id;
"Description" = $newTenant.Description;
"Enabled" = $newTenant.Enabled;
"LastResult" = $newTenant.LastResult;
"Name" = $newTenant.Name;
"Storage" = $newTenant.Resources;
}
}
$clients | ConvertTo-Json
现在,如果我在PowerShell中运行它,我会得到以下输出。Get-VBRCloudTenant -Name "JobName" | Select-Object * -ExcludeProperty SaltedPassword,PasswordSalt | ConvertTo-Json
{
"Enabled": true,
"LeaseExpirationEnabled": false,
"LeaseExpirationDate": null,
"Resources": [
{
"Repository": "Veeam.Backup.Core.CBackupRepository",
"RepositoryFriendlyName": "",
"RepositoryQuota": 84934656,
"RepositoryQuotaPath": "",
"UsedSpace": 37717110,
"PerformanceTierUsedSpace": 0,
"CapacityTierUsedSpace": 0,
"ArchiveTierUsedSpace": 0,
"UsedSpacePercentage": 44.4,
"WanAccelerationEnabled": false,
"WanAccelerator": null,
"Id": "bc978335-a0e1-4c9f-9421-d19e215aefaa"
},
{
"Repository": "Veeam.Backup.Core.CBackupRepository",
"RepositoryFriendlyName": "",
"RepositoryQuota": 15728640,
"RepositoryQuotaPath": "",
"UsedSpace": 15458718,
"PerformanceTierUsedSpace": 0,
"CapacityTierUsedSpace": 0,
"ArchiveTierUsedSpace": 0,
"UsedSpacePercentage": 98.3,
"WanAccelerationEnabled": false,
"WanAccelerator": null,
"Id": "b31975e2-58bd-40d3-b6b6-61e76e4371ac"
},
{
"Repository": "Veeam.Backup.Core.CBackupRepository",
"RepositoryFriendlyName": "",
"RepositoryQuota": 52428800,
"RepositoryQuotaPath": "",
"UsedSpace": 35513719,
"PerformanceTierUsedSpace": 0,
"CapacityTierUsedSpace": 0,
"ArchiveTierUsedSpace": 0,
"UsedSpacePercentage": 67.7,
"WanAccelerationEnabled": false,
"WanAccelerator": null,
"Id": "4ba334eb-1316-46cf-a2f7-08a4f726a1ed"
}
],
"VMCount": 0,
"ReplicaCount": 0,
"LastActive": "1/8/2021 1:09 PM",
"LastResult": "Success",
"ResourcesEnabled": true,
"ReplicationResourcesEnabled": false,
"ThrottlingEnabled": false,
"ThrottlingValue": 1,
"ThrottlingUnit": 1,
"MaxConcurrentTask": 6,
"ReplicationResources": null,
"WorkstationCount": 0,
"ServerCount": 0,
"BackupProtectionEnabled": false,
"BackupProtectionPeriod": 1,
"Type": 0,
"GatewaySelectionType": 0,
"GatewayPool": [
],
"GatewayFailoverEnabled": false,
"NewVMBackupCount": 0,
"NewWorkstationBackupCount": 0,
"NewServerBackupCount": 0,
"RentalVMBackupCount": 0,
"RentalWorkstationBackupCount": 0,
"RentalServerBackupCount": 0,
"RentalReplicaCount": 0,
"NewReplicaCount": 0,
"Id": "10904f6b-1e5d-47dc-8fa6-364e627dd9ce",
"Name": "",
"Description": ""
}
所以这是预期的,所以我在Get-VBRCloudTenant
上做了一个for each循环,我认为它可以工作,但它没有工作,我得到了这个输出。我正在做一个自定义对象,因为我不需要所有其他信息。
[
{
"Id": "f1d3acd6-bd95-4ee7-8728-0243a4506523",
"Description": "",
"Storage": [
"f020393f-afe2-4340-9a9f-23420ce8af70"
],
"LastResult": "Success",
"Name": "",
"LastActive": "2/25/2021 3:42 PM",
"Enabled": true
},
{
"Id": "10904f6b-1e5d-47dc-8fa6-364e627dd9ce",
"Description": "",
"Storage": [
"bc978335-a0e1-4c9f-9421-d19e215aefaa",
"b31975e2-58bd-40d3-b6b6-61e76e4371ac",
"4ba334eb-1316-46cf-a2f7-08a4f726a1ed"
],
"LastResult": "Success",
"Name": "",
"LastActive": "1/8/2021 1:09 PM",
"Enabled": true
}
]
如果有人能给我指出正确的方向,那就太好了。
发布于 2021-04-08 18:32:44
解决了我的问题。那是ConvertTo-Json
。默认情况下,它的最大深度只有2,所以当它到达Resources
对象时,它就停止了。我将它的深度增加到3,它完全按照我想要的那样工作。
现在我只需要运行它来获得我想要的东西。
Get-VBRCloudTenant | Select-Object * -ExcludeProperty SaltedPassword,PasswordSalt | ConvertTo-Json -Depth 3
https://stackoverflow.com/questions/67009470
复制相似问题