Inheritance: AzureRMBackupRetentionPolicy
        private static CSMMonthlyRetentionSchedule ConvertToGetCSMMonthlyRetentionObject(AzureBackupMonthlyRetentionPolicy retentionPolicy, IList<DateTime> RetentionTimes)
        {
            CSMMonthlyRetentionSchedule csmMonthlyRetention = new CSMMonthlyRetentionSchedule();

            if (retentionPolicy.RetentionFormat == RetentionFormat.Daily)
            {
                csmMonthlyRetention.RetentionScheduleType = RetentionScheduleFormat.Daily;
                csmMonthlyRetention.RetentionScheduleDaily = new CSMDailyRetentionFormat();
                csmMonthlyRetention.RetentionScheduleDaily.DaysOfTheMonth = ConvertToCSMDayList(retentionPolicy.DaysOfMonth);
            }

            else if (retentionPolicy.RetentionFormat == RetentionFormat.Weekly)
            {
                csmMonthlyRetention.RetentionScheduleWeekly = new CSMWeeklyRetentionFormat();
                csmMonthlyRetention.RetentionScheduleType = RetentionScheduleFormat.Weekly;
                csmMonthlyRetention.RetentionScheduleWeekly.DaysOfTheWeek = retentionPolicy.DaysOfWeek;
                csmMonthlyRetention.RetentionScheduleWeekly.WeeksOfTheMonth = retentionPolicy.WeekNumber;
            }

            csmMonthlyRetention.CSMRetentionDuration = new CSMRetentionDuration();
            csmMonthlyRetention.CSMRetentionDuration.Count = retentionPolicy.Retention;
            csmMonthlyRetention.CSMRetentionDuration.DurationType = RetentionDurationType.Months;
            csmMonthlyRetention.RetentionTimes = RetentionTimes;

            return csmMonthlyRetention;
        }
        private static void ValidateMonthlyRetention(AzureBackupMonthlyRetentionPolicy monthlyRetention)
        {
            if (monthlyRetention.Retention < MinRetention || monthlyRetention.Retention > MaxRetentionInMonths)
            {
                var exception = new ArgumentException(string.Format(Resources.MonthlyRetentionPolicyValueException, MinRetention, MaxRetentionInMonths));
                throw exception;
            }

            if(monthlyRetention.RetentionFormat == RetentionFormat.Daily)
            {
                if(monthlyRetention.DaysOfMonth == null || monthlyRetention.DaysOfMonth.Count == 0)
                {
                    var exception = new ArgumentException(Resources.MonthlyRetentionPolicyDaysOfMonthParamException);
                    throw exception;
                }

                if(monthlyRetention.DaysOfWeek != null || monthlyRetention.WeekNumber != null)
                {
                    var exception = new ArgumentException(Resources.MonthlyRetentionPolicyDaysOfWeekParamException);
                    throw exception;
                }
            }

            if (monthlyRetention.RetentionFormat == RetentionFormat.Weekly)
            {
                if (monthlyRetention.DaysOfWeek == null || monthlyRetention.DaysOfWeek.Count == 0)
                {
                    var exception = new ArgumentException(Resources.MonthlyRetentionPolicyDaysOfWeekException);
                    throw exception;
                }

                if (monthlyRetention.WeekNumber == null || monthlyRetention.WeekNumber.Count == 0)
                {
                    var exception = new ArgumentException(Resources.MonthlyRetentionPolicyWeekNumException);
                    throw exception;
                }

                if (monthlyRetention.DaysOfMonth != null)
                {
                    var exception = new ArgumentException(Resources.MonthlyRetentionPolicyDaysOfMonthsException);
                    throw exception;
                }
            }
        }
        private static AzureBackupMonthlyRetentionPolicy ConvertToPowershellMonthlyRetentionObject(CSMMonthlyRetentionSchedule MonthlySchedule)
        {
            if (MonthlySchedule == null)
                return null;
            AzureBackupMonthlyRetentionPolicy monthlyRetention = null;

            RetentionFormat retentionFormat = (RetentionFormat)Enum.Parse(typeof(RetentionFormat), MonthlySchedule.RetentionScheduleType.ToString(), true);
            if (retentionFormat == RetentionFormat.Daily)
            {
                List<string> dayList = ConvertToPowershellDayList(MonthlySchedule.RetentionScheduleDaily.DaysOfTheMonth);
                monthlyRetention = new AzureBackupMonthlyRetentionPolicy("Monthly", MonthlySchedule.CSMRetentionDuration.Count,
                retentionFormat, dayList, null, null);
            }
            else if (retentionFormat == RetentionFormat.Weekly)
            {
                List<WeekNumber> weekNumberList = ConvertToPowershellWeekNumberList(MonthlySchedule.RetentionScheduleWeekly);
                List<DayOfWeek> dayOfWeekList = ConvertToPowershellWeekDaysList(MonthlySchedule.RetentionScheduleWeekly);
                monthlyRetention = new AzureBackupMonthlyRetentionPolicy("Monthly", MonthlySchedule.CSMRetentionDuration.Count,
                retentionFormat, null, weekNumberList, dayOfWeekList);
            }

            monthlyRetention.RetentionTimes = MonthlySchedule.RetentionTimes;
            return monthlyRetention;
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                if (DailyRetention != false)
                {
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupDailyRetentionPolicy(RetentionType.Daily.ToString(), Retention);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });
                    WriteObject(retentionPolicy);
                }

                if (WeeklyRetention != false)
                {
                    List<DayOfWeek> daysofWeekList = ConvertDaysOfWeek(DaysOfWeek);
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupWeeklyRetentionPolicy(RetentionType.Weekly.ToString(), Retention, daysofWeekList);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });
                    WriteObject(retentionPolicy);
                }

                if (MonthlyRetentionInDailyFormat != false)
                {
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupMonthlyRetentionPolicy(RetentionType.Monthly.ToString(), Retention, RetentionFormat.Daily, DaysOfMonth,
                        null, null);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });
                    WriteObject(retentionPolicy);
                }

                if (MonthlyRetentionInWeeklyFormat != false)
                {
                    List<DayOfWeek> daysofWeekList = ConvertDaysOfWeek(DaysOfWeek);
                    List<WeekNumber> weekNumbers = ConvertWeekNumbers(WeekNumber);
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupMonthlyRetentionPolicy(RetentionType.Monthly.ToString(), Retention, RetentionFormat.Weekly, DaysOfMonth,
                        weekNumbers, daysofWeekList);

                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });

                    WriteObject(retentionPolicy);
                }

                if (YearlyRetentionInDailyFormat != false)
                {
                    List<Month> monthsOfYear = ConvertMonthsOfYear(MonthsOfYear);
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupYearlyRetentionPolicy(RetentionType.Yearly.ToString(), Retention, monthsOfYear, RetentionFormat.Daily,
                        DaysOfMonth, null, null);

                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });

                    WriteObject(retentionPolicy);
                }

                if (YearlyRetentionInWeeklyFormat != false)
                {
                    List<DayOfWeek> daysofWeekList = ConvertDaysOfWeek(DaysOfWeek);
                    List<WeekNumber> weekNumbers = ConvertWeekNumbers(WeekNumber);
                    List<Month> monthsOfYear = ConvertMonthsOfYear(MonthsOfYear);
                    AzureRMBackupRetentionPolicy retentionPolicy = new AzureBackupYearlyRetentionPolicy(RetentionType.Yearly.ToString(), Retention, monthsOfYear,
                        RetentionFormat.Weekly, DaysOfMonth, weekNumbers, daysofWeekList);

                    ProtectionPolicyHelpers.ValidateRetentionPolicy(new List<AzureRMBackupRetentionPolicy> { retentionPolicy });

                    WriteObject(retentionPolicy);
                }
            });
        }