/// <summary> /// End processing /// </summary> protected override void EndProcessing() { foreach (UpdatableHelpExceptionContext exception in _exceptions.Values) { UpdatableHelpExceptionContext e = exception; if ((exception.Exception.FullyQualifiedErrorId == "HelpCultureNotSupported") && ((exception.Cultures != null && exception.Cultures.Count > 1) || (exception.Modules != null && exception.Modules.Count > 1))) { // Win8: 744749 Rewriting the error message only in the case where either // multiple cultures or multiple modules are involved. e = new UpdatableHelpExceptionContext(new UpdatableHelpSystemException( "HelpCultureNotSupported", StringUtil.Format(HelpDisplayStrings.CannotMatchUICulturePattern, string.Join(", ", exception.Cultures)), ErrorCategory.InvalidArgument, exception.Cultures, null)); e.Modules = exception.Modules; e.Cultures = exception.Cultures; } WriteError(e.CreateErrorRecord(_commandType)); LogContext context = MshLog.GetLogContext(Context, MyInvocation); context.Severity = "Error"; PSEtwLog.LogOperationalError(PSEventId.Pipeline_Detail, PSOpcode.Exception, PSTask.ExecutePipeline, context, e.GetExceptionMessage(_commandType)); } }
protected override void ProcessRecord() { string shellID = base.Context.ShellID; string executionPolicy = SecuritySupport.GetExecutionPolicy(this.ExecutionPolicy); if (this.ShouldProcessPolicyChange(executionPolicy)) { SecuritySupport.SetExecutionPolicy(this.executionPolicyScope, this.ExecutionPolicy, shellID); if (this.ExecutionPolicy != ExecutionPolicy.Undefined) { string str = SecuritySupport.GetExecutionPolicy(shellID).ToString(); if (!string.Equals(str, executionPolicy, StringComparison.OrdinalIgnoreCase)) { string str1 = StringUtil.Format(ExecutionPolicyCommands.ExecutionPolicyOverridden, str); string executionPolicyOverriddenRecommendedAction = ExecutionPolicyCommands.ExecutionPolicyOverriddenRecommendedAction; ErrorRecord errorRecord = new ErrorRecord(new SecurityException(), "ExecutionPolicyOverride", ErrorCategory.PermissionDenied, null); errorRecord.ErrorDetails = new ErrorDetails(str1); errorRecord.ErrorDetails.RecommendedAction = executionPolicyOverriddenRecommendedAction; base.ThrowTerminatingError(errorRecord); } } PSSQMAPI.UpdateExecutionPolicy(shellID, this.ExecutionPolicy); PSEtwLog.LogSettingsEvent(MshLog.GetLogContext(base.Context, base.MyInvocation), EtwLoggingStrings.ExecutionPolicyName, executionPolicy, null); } }
internal void LogMessage(string message) { List <string> pipelineExecutionDetail = new List <string> { message }; PSEtwLog.LogPipelineExecutionDetailEvent(MshLog.GetLogContext(base.Context, base.Context.CurrentCommandProcessor.Command.MyInvocation), pipelineExecutionDetail); }
/// <summary> /// Logs a command message /// </summary> /// <param name="message">Message to log.</param> internal void LogMessage(string message) { List <string> details = new List <string>(); details.Add(message); #if !CORECLR // TODO:CORECLR Uncomment when we add PSEtwLog support PSEtwLog.LogPipelineExecutionDetailEvent(MshLog.GetLogContext(Context, Context.CurrentCommandProcessor.Command.MyInvocation), details); #endif }
/// <summary> /// Logs a command message. /// </summary> /// <param name="message">Message to log.</param> internal void LogMessage(string message) { List <string> details = new List <string>() { message }; PSEtwLog.LogPipelineExecutionDetailEvent(MshLog.GetLogContext(Context, Context.CurrentCommandProcessor.Command.MyInvocation), details); }
/// <summary> /// Set the desired execution policy. /// </summary> protected override void ProcessRecord() { string shellId = base.Context.ShellID; string executionPolicy = SecuritySupport.GetExecutionPolicy(ExecutionPolicy); if (ShouldProcessPolicyChange(executionPolicy)) { try { SecuritySupport.SetExecutionPolicy(_executionPolicyScope, ExecutionPolicy, shellId); } catch (UnauthorizedAccessException exception) { OnAccessDeniedError(exception); } catch (System.Security.SecurityException exception) { OnAccessDeniedError(exception); } // Ensure it is now the effective execution policy if (ExecutionPolicy != ExecutionPolicy.Undefined) { string effectiveExecutionPolicy = SecuritySupport.GetExecutionPolicy(shellId).ToString(); if (!string.Equals(effectiveExecutionPolicy, executionPolicy, StringComparison.OrdinalIgnoreCase)) { string message = StringUtil.Format(ExecutionPolicyCommands.ExecutionPolicyOverridden, effectiveExecutionPolicy); string recommendedAction = ExecutionPolicyCommands.ExecutionPolicyOverriddenRecommendedAction; ErrorRecord errorRecord = new ErrorRecord( new System.Security.SecurityException(), "ExecutionPolicyOverride", ErrorCategory.PermissionDenied, null); errorRecord.ErrorDetails = new ErrorDetails(message); errorRecord.ErrorDetails.RecommendedAction = recommendedAction; ThrowTerminatingError(errorRecord); } } #if !CORECLR PSEtwLog.LogSettingsEvent(MshLog.GetLogContext(Context, MyInvocation), EtwLoggingStrings.ExecutionPolicyName, executionPolicy, null); #endif } }//End ProcessRecord()
protected override void EndProcessing() { foreach (UpdatableHelpExceptionContext context in this.exceptions.Values) { UpdatableHelpExceptionContext context2 = context; if ((context.Exception.FullyQualifiedErrorId == "HelpCultureNotSupported") && (((context.Cultures != null) && (context.Cultures.Count > 1)) || ((context.Modules != null) && (context.Modules.Count > 1)))) { context2 = new UpdatableHelpExceptionContext(new UpdatableHelpSystemException("HelpCultureNotSupported", StringUtil.Format(HelpDisplayStrings.CannotMatchUICulturePattern, string.Join(", ", context.Cultures)), ErrorCategory.InvalidArgument, context.Cultures, null)) { Modules = context.Modules, Cultures = context.Cultures }; } base.WriteError(context2.CreateErrorRecord(this._commandType)); LogContext logContext = MshLog.GetLogContext(base.Context, base.MyInvocation); logContext.Severity = "Error"; PSEtwLog.LogOperationalError(PSEventId.Pipeline_Detail, PSOpcode.Exception, PSTask.ExecutePipeline, logContext, context2.GetExceptionMessage(this._commandType)); } }