So I am not very well versed in PowerShell and I don't know how to make this work the way I want. I've tried googling for a solution but I couldn't find anything for what I was trying to do. Not sure if I just wasn't searching for the right thing. Anyways, what I am trying to do is expand an object that's returned. Now it works fine when it's just one but when there are multiple it just outputs an array. This is for Veeam Powershell commands if that helps.
$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
Now if I run this in PowerShell I get this output.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": ""
}
So this works as intended so I went and did a for each loop on Get-VBRCloudTenant
thinking it would work but it doesn't. I get this output instead. I am doing a custom object as I don't need all of the other information.
[
{
"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
}
]
If someone can point me in the right direction that would be great.
Figured out my problem. It was the ConvertTo-Json
. It only has a max depth of 2 by default so it was stopping right when it got to the Resources
object. I increased it to a depth of 3 and it worked exactly as I wanted.
Now I just need to run this to get what I want.
Get-VBRCloudTenant | Select-Object * -ExcludeProperty SaltedPassword,PasswordSalt | ConvertTo-Json -Depth 3