Add multiple Tenants to machine via API script

Hi,

Im sure this is really simple but I built some new machines that I want to add the Tenants to these based on an exisiting machine.

I can pull the tenantsids using from the current machine using the tenantids property:

$Tenantid = $Repository.machines.Findbyname(“xxxxxxxx”)

I thought this would work:

foreach ($machine in $machines) {
$machine.TenantIds.Add($Tenantid)
$repository.Machines.Add($machine)
}

but I cant add seem to add in multiple tenants
Error i get is:

Exception calling “Modify” with “1” argument(s): "There was a problem with your request.

Hi Craig,

Thanks for getting in touch! In order to add multiple Tenants this way, you will need to pass through a single tenant at a time.

I had this working by doing something like the following:

foreach ($machine in $machines)
{
    $modify = $repository.Machines.Get($machine.Id)
    $modify.TenantIds.Add("Tenants-81")
    $modify.TenantIds.Add("Tenants-82")
    $repository.Machines.Modify($modify)
}

Does this help you achieve what you are after here?

Looking forward to hearing from you.

Best regards,
Daniel

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.