public override void ExecuteCmdlet() { base.ExecuteCmdlet(); PSManagementPolicyActionGroup action = InputObject; if (action is null) { action = new PSManagementPolicyActionGroup(); } switch (this.ParameterSetName) { case BaseBlobParameterSet: if (action.BaseBlob is null) { action.BaseBlob = new PSManagementPolicyBaseBlob(); } switch (BaseBlobAction) { case ManagementPolicyAction.Delete: action.BaseBlob.Delete = new PSDateAfterModification(this.DaysAfterModificationGreaterThan); break; case ManagementPolicyAction.TierToCool: action.BaseBlob.TierToCool = new PSDateAfterModification(this.DaysAfterModificationGreaterThan); break; case ManagementPolicyAction.TierToArchive: action.BaseBlob.TierToArchive = new PSDateAfterModification(this.DaysAfterModificationGreaterThan); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid BaseBlobAction: {0}", this.BaseBlobAction)); } break; case SnapshotParameterSet: if (action.Snapshot is null) { action.Snapshot = new PSManagementPolicySnapShot(); } action.Snapshot.Delete = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ParameterSet: {0}", this.ParameterSetName)); } WriteObject(action); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); PSManagementPolicyActionGroup action = InputObject; if (action is null) { action = new PSManagementPolicyActionGroup(); } switch (this.ParameterSetName) { case BaseBlobParameterSet: case BaseBlobLastAccessTimeParameterSet: if (action.BaseBlob is null) { action.BaseBlob = new PSManagementPolicyBaseBlob(); } if (this.daysAfterLastTierChangeGreaterThan != null & BaseBlobAction != ManagementPolicyAction.TierToArchive & SnapshotAction != ManagementPolicyAction.TierToArchive & BlobVersionAction != ManagementPolicyAction.TierToArchive) { throw new PSArgumentException("-DaysAfterLastTierChangeGreaterThan is only avaialbe with action TierToArchive.", "DaysAfterLastTierChangeGreaterThan"); } int?daysAfterCreationGreaterThan = this.DaysAfterCreationGreaterThan; if (daysAfterCreationGreaterThan == 0) { daysAfterCreationGreaterThan = null; } switch (BaseBlobAction) { case ManagementPolicyAction.Delete: action.BaseBlob.Delete = new PSDateAfterModification(this.daysAfterModificationGreaterThan, this.daysAfterLastAccessTimeGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToCool: action.BaseBlob.TierToCool = new PSDateAfterModification(this.daysAfterModificationGreaterThan, this.daysAfterLastAccessTimeGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToArchive: action.BaseBlob.TierToArchive = new PSDateAfterModification(this.daysAfterModificationGreaterThan, this.daysAfterLastAccessTimeGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid BaseBlobAction: {0}", this.BaseBlobAction)); } if (this.EnableAutoTierToHotFromCool.IsPresent) { action.BaseBlob.EnableAutoTierToHotFromCool = true; } break; case SnapshotParameterSet: if (action.Snapshot is null) { action.Snapshot = new PSManagementPolicySnapShot(); } switch (SnapshotAction) { case ManagementPolicyAction.Delete: action.Snapshot.Delete = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToCool: action.Snapshot.TierToCool = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToArchive: action.Snapshot.TierToArchive = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid SnapshotAction: {0}", this.SnapshotAction)); } break; case BlobVersionParameterSet: if (action.Version is null) { action.Version = new PSManagementPolicyVersion(); } switch (BlobVersionAction) { case ManagementPolicyAction.Delete: action.Version.Delete = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToCool: action.Version.TierToCool = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; case ManagementPolicyAction.TierToArchive: action.Version.TierToArchive = new PSDateAfterCreation(this.DaysAfterCreationGreaterThan, this.daysAfterLastTierChangeGreaterThan); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid BlobVersionAction: {0}", this.BlobVersionAction)); } break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ParameterSet: {0}", this.ParameterSetName)); } WriteObject(action); }