/// <summary> /// Executes the cmdlet. /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { CheckNameAvailabilityResult checkNameAvailabilityResult = StorageSyncClientWrapper.StorageSyncManagementClient.StorageSyncServices.CheckNameAvailability(Location.Replace(" ", string.Empty), Name); if (!checkNameAvailabilityResult.NameAvailable.Value) { throw new PSArgumentException(checkNameAvailabilityResult.Message, nameof(Name)); } var createParameters = new StorageSyncServiceCreateParameters() { Location = Location, Tags = TagsConversionHelper.CreateTagDictionary(Tag ?? new Hashtable(), validate: true), }; Target = string.Join("/", ResourceGroupName, Name); if (ShouldProcess(Target, ActionMessage)) { StorageSyncModels.StorageSyncService storageSyncService = StorageSyncClientWrapper.StorageSyncManagementClient.StorageSyncServices.Create(ResourceGroupName, Name, createParameters); WriteObject(storageSyncService); } }); }
/// <summary> /// Executes the cmdlet. /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { var resourceName = default(string); var resourceGroupName = default(string); // Handle ResourceId Parameter Set if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(ResourceId); resourceName = resourceIdentifier.ResourceName; resourceGroupName = resourceIdentifier.ResourceGroupName; } else if (this.IsParameterBound(c => c.InputObject)) { resourceName = InputObject.StorageSyncServiceName; resourceGroupName = InputObject.ResourceGroupName; } else { resourceName = Name; resourceGroupName = ResourceGroupName; } string incomingTrafficPolicy; if (this.IsParameterBound(c => c.IncomingTrafficPolicy)) { if (string.IsNullOrEmpty(this.IncomingTrafficPolicy)) { throw new PSArgumentException(nameof(IncomingTrafficPolicy)); } incomingTrafficPolicy = this.IncomingTrafficPolicy; } else { incomingTrafficPolicy = StorageSyncModels.IncomingTrafficPolicy.AllowAllTraffic; } var updateParameters = new StorageSyncServiceUpdateParameters() { Tags = TagsConversionHelper.CreateTagDictionary(Tag ?? new Hashtable(), validate: true), IncomingTrafficPolicy = incomingTrafficPolicy }; Target = string.Join("/", resourceGroupName, resourceName); if (ShouldProcess(Target, ActionMessage)) { StorageSyncModels.StorageSyncService storageSyncService = StorageSyncClientWrapper.StorageSyncManagementClient.StorageSyncServices.Update(ResourceGroupName, Name, updateParameters); WriteObject(storageSyncService); } }); }
/// <summary> /// Writes the object. /// </summary> /// <param name="resource">The resource.</param> protected void WriteObject(StorageSyncModels.StorageSyncService resource) { WriteObject(new StorageSyncServiceConverter().Convert(resource)); }