public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ConfigurationAssignmentName, VerbsCommon.Remove) &&
                    (this.Force.IsPresent ||
                     this.ShouldContinue(Properties.Resources.ResourceRemovalConfirmation,
                                         "Remove-AzConfigurationAssignment operation")))
                {
                    string resourceGroupName           = this.ResourceGroupName;
                    string providerName                = this.ProviderName;
                    string resourceParentType          = this.ResourceParentType;
                    string resourceParentName          = this.ResourceParentName;
                    string resourceType                = this.ResourceType;
                    string resourceName                = this.ResourceName;
                    string configurationAssignmentName = this.ConfigurationAssignmentName;

                    if (!string.IsNullOrEmpty(resourceParentType) && !string.IsNullOrEmpty(resourceParentName))
                    {
                        ConfigurationAssignmentsClient.DeleteParent(resourceGroupName, providerName, resourceParentType, resourceParentName, resourceType, resourceName, configurationAssignmentName);
                    }
                    else
                    {
                        ConfigurationAssignmentsClient.Delete(resourceGroupName, providerName, resourceType, resourceName, configurationAssignmentName);
                    }

                    if (this.PassThru.IsPresent)
                    {
                        this.WriteObject(true);
                    }
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ConfigurationAssignmentName, VerbsCommon.New))
                {
                    string resourceGroupName           = this.ResourceGroupName;
                    string providerName                = this.ProviderName;
                    string resourceParentType          = this.ResourceParentType;
                    string resourceParentName          = this.ResourceParentName;
                    string resourceType                = this.ResourceType;
                    string resourceName                = this.ResourceName;
                    string configurationAssignmentName = this.ConfigurationAssignmentName;
                    var configurationAssignment        = new ConfigurationAssignment();
                    configurationAssignment.ResourceId = this.ResourceId;

                    configurationAssignment.Location = this.Location;
                    configurationAssignment.MaintenanceConfigurationId = this.MaintenanceConfigurationId;

                    var result = (!string.IsNullOrEmpty(resourceParentType) && !string.IsNullOrEmpty(resourceParentName)) ?
                                 ConfigurationAssignmentsClient.CreateOrUpdateParent(resourceGroupName, providerName, resourceParentType, resourceParentName, resourceType, resourceName, configurationAssignmentName, configurationAssignment) :
                                 ConfigurationAssignmentsClient.CreateOrUpdate(resourceGroupName, providerName, resourceType, resourceName, configurationAssignmentName, configurationAssignment);

                    var psObject = new PSConfigurationAssignment();
                    MaintenanceAutomationAutoMapperProfile.Mapper.Map <ConfigurationAssignment, PSConfigurationAssignment>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Exemple #3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName  = this.ResourceGroupName;
                string providerName       = this.ProviderName;
                string resourceParentType = this.ResourceParentType;
                string resourceParentName = this.ResourceParentName;
                string resourceType       = this.ResourceType;
                string resourceName       = this.ResourceName;

                var result = (!string.IsNullOrEmpty(resourceParentType) && !string.IsNullOrEmpty(resourceParentName)) ?
                             ConfigurationAssignmentsClient.ListParent(resourceGroupName, providerName, resourceParentType, resourceParentName, resourceType, resourceName) :
                             ConfigurationAssignmentsClient.List(resourceGroupName, providerName, resourceType, resourceName);

                var psObject = new List <PSConfigurationAssignment>();

                foreach (var configurationAssignment in result)
                {
                    PSConfigurationAssignment psConfigurationAssignment = new PSConfigurationAssignment();
                    MaintenanceAutomationAutoMapperProfile.Mapper.Map <ConfigurationAssignment, PSConfigurationAssignment>(configurationAssignment, psConfigurationAssignment);
                    psObject.Add(psConfigurationAssignment);
                }

                WriteObject(psObject);
            });
        }