public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName                = this.ResourceGroupName;
                    string galleryName                      = this.GalleryName;
                    string galleryImageName                 = this.GalleryImageDefinitionName;
                    string galleryImageVersionName          = this.Name;
                    GalleryImageVersion galleryImageVersion = new GalleryImageVersion();

                    galleryImageVersion.Location                 = this.Location;
                    galleryImageVersion.PublishingProfile        = new GalleryImageVersionPublishingProfile();
                    galleryImageVersion.PublishingProfile.Source = new GalleryArtifactSource();
                    galleryImageVersion.PublishingProfile.Source.ManagedImage    = new ManagedArtifact();
                    galleryImageVersion.PublishingProfile.Source.ManagedImage.Id = this.SourceImageId;

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }

                    if (this.IsParameterBound(c => c.ReplicaCount))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
                    }

                    if (this.IsParameterBound(c => c.StorageAccountType))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.StorageAccountType = this.StorageAccountType;
                    }

                    if (this.IsParameterBound(c => c.TargetRegion))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>();
                        foreach (var t in this.TargetRegion)
                        {
                            galleryImageVersion.PublishingProfile.TargetRegions.Add(new TargetRegion((string)t["Name"], (int?)t["ReplicaCount"], (string)t["StorageAccountType"]));
                        }
                    }

                    var result   = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion);
                    var psObject = new PSGalleryImageVersion();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsData.Update))
                {
                    string resourceGroupName;
                    string galleryName;
                    string galleryImageName;
                    string galleryImageVersionName;
                    switch (this.ParameterSetName)
                    {
                    case "ResourceIdParameter":
                        resourceGroupName       = GetResourceGroupName(this.ResourceId);
                        galleryName             = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageName        = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageVersionName = GetVersion(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        break;

                    case "ObjectParameter":
                        resourceGroupName       = GetResourceGroupName(this.InputObject.Id);
                        galleryName             = GetResourceName(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageName        = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageVersionName = GetVersion(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        break;

                    default:
                        resourceGroupName       = this.ResourceGroupName;
                        galleryName             = this.GalleryName;
                        galleryImageName        = this.GalleryImageDefinitionName;
                        galleryImageVersionName = this.Name;
                        break;
                    }

                    var galleryImageVersion = new GalleryImageVersion();

                    if (this.ParameterSetName == "ObjectParameter")
                    {
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSGalleryImageVersion, GalleryImageVersion>(this.InputObject, galleryImageVersion);
                    }
                    else
                    {
                        galleryImageVersion = GalleryImageVersionsClient.Get(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName);
                    }

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }

                    if (this.IsParameterBound(c => c.ReplicaCount))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
                    }

                    if (this.IsParameterBound(c => c.TargetRegion))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>();
                        foreach (var t in this.TargetRegion)
                        {
                            galleryImageVersion.PublishingProfile.TargetRegions.Add(new TargetRegion((string)t["Name"], (int?)t["ReplicaCount"]));
                        }
                    }

                    var result   = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion);
                    var psObject = new PSGalleryImageVersion();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsData.Update))
                {
                    string resourceGroupName;
                    string galleryName;
                    string galleryImageName;
                    string galleryImageVersionName;
                    switch (this.ParameterSetName)
                    {
                    case "ResourceIdParameter":
                        resourceGroupName       = GetResourceGroupName(this.ResourceId);
                        galleryName             = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageName        = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageVersionName = GetVersion(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions");
                        break;

                    case "ObjectParameter":
                        resourceGroupName       = GetResourceGroupName(this.InputObject.Id);
                        galleryName             = GetResourceName(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageName        = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        galleryImageVersionName = GetVersion(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions");
                        break;

                    default:
                        resourceGroupName       = this.ResourceGroupName;
                        galleryName             = this.GalleryName;
                        galleryImageName        = this.GalleryImageDefinitionName;
                        galleryImageVersionName = this.Name;
                        break;
                    }

                    var galleryImageVersion = new GalleryImageVersion();

                    if (this.ParameterSetName == "ObjectParameter")
                    {
                        ComputeAutomationAutoMapperProfile.Mapper.Map <PSGalleryImageVersion, GalleryImageVersion>(this.InputObject, galleryImageVersion);
                    }
                    else
                    {
                        galleryImageVersion = GalleryImageVersionsClient.Get(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName);
                    }

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }

                    if (this.IsParameterBound(c => c.ReplicaCount))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
                    }

                    if (this.IsParameterBound(c => c.TargetRegion))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>();
                        foreach (var t in this.TargetRegion)
                        {
                            var target = new TargetRegion()
                            {
                                Name = (string)t["Name"],
                                RegionalReplicaCount = (int?)t["ReplicaCount"],
                                StorageAccountType   = (string)t["StorageAccountType"],
                            };
                            if (t["Encryption"] != null)
                            {
                                var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"];
                                var osDiskImageEncryption = new OSDiskImageEncryption(osDiskEncryptionSetId);

                                List <DataDiskImageEncryption> dataDiskImageEncryption = null;
                                var dataDiskImage = (object[])((Hashtable)t["Encryption"])["dataDiskImages"];

                                if (dataDiskImage != null)
                                {
                                    dataDiskImageEncryption = new List <DataDiskImageEncryption>();
                                    foreach (Hashtable dataDiskEncryptionSetId in dataDiskImage)
                                    {
                                        DataDiskImageEncryption d = new DataDiskImageEncryption((int)dataDiskEncryptionSetId["Lun"], (string)dataDiskEncryptionSetId["DiskEncryptionSetId"]);
                                        dataDiskImageEncryption.Add(d);
                                    }
                                }

                                target.Encryption = new EncryptionImages(osDiskImageEncryption, dataDiskImageEncryption);
                            }

                            galleryImageVersion.PublishingProfile.TargetRegions.Add(target);
                        }
                    }

                    if (galleryImageVersion.StorageProfile != null && galleryImageVersion.StorageProfile.Source != null && galleryImageVersion.StorageProfile.Source.Id != null)
                    {
                        galleryImageVersion.StorageProfile.Source.Id = null;
                    }

                    galleryImageVersion.StorageProfile.DataDiskImages = null;
                    galleryImageVersion.StorageProfile.OsDiskImage    = null;

                    var result   = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion);
                    var psObject = new PSGalleryImageVersion();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName                = this.ResourceGroupName;
                    string galleryName                      = this.GalleryName;
                    string galleryImageName                 = this.GalleryImageDefinitionName;
                    string galleryImageVersionName          = this.Name;
                    GalleryImageVersion galleryImageVersion = new GalleryImageVersion();

                    galleryImageVersion.Location = this.Location;

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }

                    if (this.IsParameterBound(c => c.DataDiskImage))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        galleryImageVersion.StorageProfile.DataDiskImages = this.DataDiskImage;
                    }

                    if (this.IsParameterBound(c => c.OSDiskImage))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        galleryImageVersion.StorageProfile.OsDiskImage = this.OSDiskImage;
                    }

                    if (this.IsParameterBound(c => c.ReplicaCount))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
                    }

                    if (this.IsParameterBound(c => c.StorageAccountType))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.StorageAccountType = this.StorageAccountType;
                    }

                    if (this.IsParameterBound(c => c.TargetRegion))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>();
                        foreach (var t in this.TargetRegion)
                        {
                            var target = new TargetRegion()
                            {
                                Name = (string)t["Name"],
                                RegionalReplicaCount = (int?)t["ReplicaCount"],
                                StorageAccountType   = (string)t["StorageAccountType"],
                            };
                            if (t["Encryption"] != null)
                            {
                                var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"];
                                var osDiskImageEncryption = new OSDiskImageEncryption(osDiskEncryptionSetId);

                                List <DataDiskImageEncryption> dataDiskImageEncryption = null;
                                var dataDiskImage = (object[])((Hashtable)t["Encryption"])["dataDiskImages"];

                                if (dataDiskImage != null)
                                {
                                    dataDiskImageEncryption = new List <DataDiskImageEncryption>();
                                    foreach (Hashtable dataDiskEncryptionSetId in dataDiskImage)
                                    {
                                        DataDiskImageEncryption d = new DataDiskImageEncryption((int)dataDiskEncryptionSetId["Lun"], (string)dataDiskEncryptionSetId["DiskEncryptionSetId"]);
                                        dataDiskImageEncryption.Add(d);
                                    }
                                }

                                target.Encryption = new EncryptionImages(osDiskImageEncryption, dataDiskImageEncryption);
                            }

                            galleryImageVersion.PublishingProfile.TargetRegions.Add(target);
                        }
                    }

                    Dictionary <string, List <string> > auxAuthHeader = null;
                    if (this.IsParameterBound(c => c.SourceImageId))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        if (galleryImageVersion.StorageProfile.Source == null)
                        {
                            galleryImageVersion.StorageProfile.Source = new GalleryArtifactVersionSource();
                        }
                        galleryImageVersion.StorageProfile.Source.Id = this.SourceImageId;

                        var resourceId = ResourceId.TryParse(this.SourceImageId);

                        if (string.Equals("galleries", resourceId?.ResourceType?.Provider, StringComparison.OrdinalIgnoreCase) &&
                            !string.Equals(this.ComputeClient?.ComputeManagementClient?.SubscriptionId, resourceId?.SubscriptionId, StringComparison.OrdinalIgnoreCase))
                        {
                            List <string> resourceIds = new List <string>();
                            resourceIds.Add(this.SourceImageId);
                            var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
                            if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
                            {
                                auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary);
                            }
                        }
                    }

                    GalleryImageVersion result;
                    if (auxAuthHeader != null)
                    {
                        var res = GalleryImageVersionsClient.CreateOrUpdateWithHttpMessagesAsync(
                            this.ResourceGroupName,
                            galleryName,
                            galleryImageName,
                            galleryImageVersionName, galleryImageVersion,
                            auxAuthHeader).GetAwaiter().GetResult();

                        result = res.Body;
                    }
                    else
                    {
                        result = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion);
                    }

                    var psObject = new PSGalleryImageVersion();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName                = this.ResourceGroupName;
                    string galleryName                      = this.GalleryName;
                    string galleryImageName                 = this.GalleryImageDefinitionName;
                    string galleryImageVersionName          = this.Name;
                    GalleryImageVersion galleryImageVersion = new GalleryImageVersion();

                    galleryImageVersion.Location = this.Location;

                    if (this.IsParameterBound(c => c.SourceImageId))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        if (galleryImageVersion.StorageProfile.Source == null)
                        {
                            galleryImageVersion.StorageProfile.Source = new GalleryArtifactVersionSource();
                        }
                        galleryImageVersion.StorageProfile.Source.Id = this.SourceImageId;
                    }

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }

                    if (this.IsParameterBound(c => c.DataDiskImage))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        galleryImageVersion.StorageProfile.DataDiskImages = this.DataDiskImage;
                    }

                    if (this.IsParameterBound(c => c.OSDiskImage))
                    {
                        if (galleryImageVersion.StorageProfile == null)
                        {
                            galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
                        }
                        galleryImageVersion.StorageProfile.OsDiskImage = this.OSDiskImage;
                    }

                    if (this.IsParameterBound(c => c.ReplicaCount))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent;
                    }

                    if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
                    }

                    if (this.IsParameterBound(c => c.StorageAccountType))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.StorageAccountType = this.StorageAccountType;
                    }

                    if (this.IsParameterBound(c => c.TargetRegion))
                    {
                        if (galleryImageVersion.PublishingProfile == null)
                        {
                            galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
                        }
                        galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>();
                        foreach (var t in this.TargetRegion)
                        {
                            var target = new TargetRegion()
                            {
                                Name = (string)t["Name"],
                                RegionalReplicaCount = (int?)t["ReplicaCount"],
                                StorageAccountType   = (string)t["StorageAccountType"],
                            };
                            if (t["Encryption"] != null)
                            {
                                var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"];
                                var osDiskImageEncryption = new OSDiskImageEncryption(osDiskEncryptionSetId);

                                List <DataDiskImageEncryption> dataDiskImageEncryption = null;
                                var dataDiskImage = (object[])((Hashtable)t["Encryption"])["dataDiskImages"];

                                if (dataDiskImage != null)
                                {
                                    dataDiskImageEncryption = new List <DataDiskImageEncryption>();
                                    foreach (Hashtable dataDiskEncryptionSetId in dataDiskImage)
                                    {
                                        DataDiskImageEncryption d = new DataDiskImageEncryption((int)dataDiskEncryptionSetId["Lun"], (string)dataDiskEncryptionSetId["DiskEncryptionSetId"]);
                                        dataDiskImageEncryption.Add(d);
                                    }
                                }

                                target.Encryption = new EncryptionImages(osDiskImageEncryption, dataDiskImageEncryption);
                            }

                            galleryImageVersion.PublishingProfile.TargetRegions.Add(target);
                        }
                    }

                    var result   = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion);
                    var psObject = new PSGalleryImageVersion();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }