diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Clone/StartAzureStorSimpleBackupCloneJob.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Clone/StartAzureStorSimpleBackupCloneJob.cs index 4dcb4d100393..2a20f15d7722 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Clone/StartAzureStorSimpleBackupCloneJob.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Clone/StartAzureStorSimpleBackupCloneJob.cs @@ -16,25 +16,39 @@ namespace Microsoft.AzureStorSimpleDeviceCmdlets.Commands /// Given a backupId, snapshot and a targetDeviceName , this commandlet will /// clone it on the given target device. /// - [Cmdlet(VerbsLifecycle.Start, "AzureStorSimpleBackupCloneJob")] + [Cmdlet(VerbsLifecycle.Start, "AzureStorSimpleBackupCloneJob", DefaultParameterSetName = StorSimpleCmdletParameterSet.Empty)] public class StartAzureStorSimpleBackupCloneJob : StorSimpleCmdletBase { - [Parameter(Mandatory = true, Position = 0, HelpMessage = StorSimpleCmdletHelpMessage.SourceDeviceName)] + [Parameter(Mandatory = true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyByName, HelpMessage = StorSimpleCmdletHelpMessage.SourceDeviceName)] + [ValidateNotNullOrEmpty] public string SourceDeviceName { get; set; } - [Parameter(Mandatory = true, Position = 1, HelpMessage = StorSimpleCmdletHelpMessage.TargetDeviceName)] + [Parameter(Mandatory = true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyById, HelpMessage = StorSimpleCmdletHelpMessage.SourceDeviceId)] + [ValidateNotNullOrEmpty] + public string SourceDeviceId { get; set; } + + [Parameter(Mandatory = true, Position = 1, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyByName, HelpMessage = StorSimpleCmdletHelpMessage.TargetDeviceName)] + [ValidateNotNullOrEmpty] public string TargetDeviceName { get; set; } + [Parameter(Mandatory = true, Position = 1, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyById, HelpMessage = StorSimpleCmdletHelpMessage.TargetDeviceId)] + [ValidateNotNullOrEmpty] + public string TargetDeviceId { get; set; } + [Parameter(Mandatory = true, Position = 2, HelpMessage = StorSimpleCmdletHelpMessage.BackupIdToClone)] + [ValidateNotNullOrEmpty] public string BackupId { get; set; } [Parameter(Mandatory = true, Position = 3, ValueFromPipeline = true, HelpMessage = StorSimpleCmdletHelpMessage.SnapshotToClone)] + [ValidateNotNull] public Snapshot Snapshot { get; set; } [Parameter(Mandatory = false, Position = 4, ValueFromPipeline = true, HelpMessage = StorSimpleCmdletHelpMessage.VolumeAcrList)] + [ValidateNotNull] public List TargetAccessControlRecords { get; set; } [Parameter(Mandatory = false, Position = 5, HelpMessage = StorSimpleCmdletHelpMessage.CloneVolumeName)] + [ValidateNotNullOrEmpty] public string CloneVolumeName { get; set; } [Parameter(Mandatory = false, Position = 6, HelpMessage = StorSimpleCmdletHelpMessage.Force)] @@ -83,22 +97,31 @@ public override void ExecuteCmdlet() private bool ProcessParameters() { - this.sourceDeviceId = StorSimpleClient.GetDeviceId(SourceDeviceName); - - if (this.sourceDeviceId == null) + switch (ParameterSetName) { - WriteVerbose(Resources.NoDeviceFoundWithGivenNameInResourceMessage); - return false; - } + case StorSimpleCmdletParameterSet.IdentifyById: + this.sourceDeviceId = SourceDeviceId; + this.targetDeviceId = TargetDeviceId; + break; + case StorSimpleCmdletParameterSet.IdentifyByName: + this.sourceDeviceId = StorSimpleClient.GetDeviceId(SourceDeviceName); + + if (this.sourceDeviceId == null) + { + WriteVerbose(Resources.NoDeviceFoundWithGivenNameInResourceMessage); + return false; + } - this.targetDeviceId = StorSimpleClient.GetDeviceId(TargetDeviceName); + this.targetDeviceId = StorSimpleClient.GetDeviceId(TargetDeviceName); - if (this.targetDeviceId == null) - { - WriteVerbose(Resources.NoDeviceFoundWithGivenNameInResourceMessage); - return false; + if (this.targetDeviceId == null) + { + WriteVerbose(Resources.NoDeviceFoundWithGivenNameInResourceMessage); + return false; + } + break; } - + return true; }