public override void ExecuteCmdlet() { CloudFile fileToBeDownloaded; string[] path = NamingUtil.ValidatePath(this.Path, true); switch (this.ParameterSetName) { case Constants.FileParameterSetName: fileToBeDownloaded = this.File; break; case Constants.ShareNameParameterSetName: var share = this.BuildFileShareObjectFromName(this.ShareName); fileToBeDownloaded = share.GetRootDirectoryReference().GetFileReferenceByPath(path); break; case Constants.ShareParameterSetName: fileToBeDownloaded = this.Share.GetRootDirectoryReference().GetFileReferenceByPath(path); break; case Constants.DirectoryParameterSetName: fileToBeDownloaded = this.Directory.GetFileReferenceByPath(path); break; default: throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName)); } string resolvedDestination = this.GetUnresolvedProviderPathFromPSPath( string.IsNullOrWhiteSpace(this.Destination) ? "." : this.Destination); FileMode mode = this.Force ? FileMode.Create : FileMode.CreateNew; string targetFile; if (LocalDirectory.Exists(resolvedDestination)) { // If the destination pointed to an existing directory, we // would download the file into the folder with the same name // on cloud. targetFile = LocalPath.Combine(resolvedDestination, fileToBeDownloaded.GetBaseName()); } else { // Otherwise we treat the destination as a file no matter if // there's one existing or not. The overwrite behavior is configured // by FileMode. targetFile = resolvedDestination; } this.RunTask(async taskId => { var downloadJob = new FileDownloadJob() { SourceFile = fileToBeDownloaded, DestPath = targetFile }; var progressRecord = new ProgressRecord( this.OutputStream.GetProgressId(taskId), string.Format(CultureInfo.CurrentCulture, Resources.ReceiveAzureFileActivity, fileToBeDownloaded.GetFullPath(), targetFile), Resources.PrepareDownloadingFile); await this.RunTransferJob(downloadJob, progressRecord); if (this.PassThru) { this.OutputStream.WriteObject(taskId, fileToBeDownloaded); } }); }