protected override void ProcessRecord() { Profile checkProfile = null; if (!string.IsNullOrEmpty(Name) && Name.Length > 0) { checkProfile = CurrentData.GetProfile(Name); } else if (InputObject != null) { checkProfile = InputObject; } /* * if (this.Name != null && * this.Name != string.Empty && * this.Name.Length > 0) { * checkProfile = * CurrentData.GetProfile(this.Name); * } else if (this.InputObject != null && * this.InputObject is Profile) { * checkProfile = * this.InputObject; * } */ WriteObject(this, checkProfile); }
protected override void BeginProcessing() { Profile profile = new Profile(Name); Profile checkProfile = CurrentData.GetProfile(profile.Name); if (checkProfile == null) { CurrentData.Profiles.Add(profile); WriteObject(this, profile); } else { // 20130323 // ErrorRecord err = // new ErrorRecord( // new Exception("The profile already exists"), // "ProfileAlreadyExists", // ErrorCategory.InvalidArgument, // profile); // err.ErrorDetails = // new ErrorDetails("The profile already exists"); // WriteError(this, err, true); WriteError( this, "The profile already exists", "ProfileAlreadyExists", ErrorCategory.InvalidArgument, true); } }