public override void ExecuteCmdlet() { if (ShouldProcess(Name, Resources.CreateNewPowerBIEmbeddedCapacity)) { try { if (PowerBIClient.GetCapacity(ResourceGroupName, Name) != null) { throw new CloudException(string.Format(Resources.PowerBIEmbeddedCapacityExists, Name)); } } catch (CloudException ex) { if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) { // capacity does not exists so go ahead and create one } else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) { // resource group not found, let create throw error don't throw from here } else { // all other exceptions should be thrown throw; } } var createdCapacity = PowerBIClient.CreateOrUpdateCapacity(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null); WriteObject(createdCapacity); } }
public override void ExecuteCmdlet() { string capacityName = Name; string resourceGroupName = ResourceGroupName; if (!string.IsNullOrEmpty(ResourceId)) { PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName); } else if (InputObject != null) { PowerBIUtils.GetResourceGroupNameAndCapacityName(InputObject.Id, out resourceGroupName, out capacityName); } if (string.IsNullOrEmpty(capacityName)) { WriteExceptionError(new PSArgumentNullException("Name", "Name of capacity not specified")); } if (ShouldProcess(capacityName, Resources.UpdatingPowerBIEmbeddedCapacity)) { PSPowerBIEmbeddedCapacity currentCapacity = null; if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out currentCapacity)) { throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName)); } var availableSkus = PowerBIClient.ListSkusForExisting(resourceGroupName, capacityName); if (Sku != null && !availableSkus.Value.Any(v => v.Sku.Name == Sku)) { throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Sku.Name)))); } var location = currentCapacity.Location; if (Tag == null && currentCapacity.Tag != null) { Tag = TagsConversionHelper.CreateTagHashtable(currentCapacity.Tag); } PSPowerBIEmbeddedCapacity updateCapacity = PowerBIClient.CreateOrUpdateCapacity(resourceGroupName, capacityName, location, Sku, Tag, Administrator, currentCapacity); if (PassThru.IsPresent) { WriteObject(updateCapacity); } } }