protected override void EndProcessing() { var stdOutHandle = NativeMethods.GetStdHandle(-11); CONSOLE_SCREEN_BUFFER_INFOEX screenBufferInfo = new CONSOLE_SCREEN_BUFFER_INFOEX { cbSize = Marshal.SizeOf <CONSOLE_SCREEN_BUFFER_INFOEX>() }; if (!NativeMethods.GetConsoleScreenBufferInfoEx(stdOutHandle, ref screenBufferInfo)) { WriteError(new ErrorRecord( null, "ErrorGettingScreenBufferInfo", ErrorCategory.InvalidOperation, "Error getting screen buffer info")); return; } if (ParameterSetName == "SingleColor") { SetColorHelper(ConsoleColor, RGB, ref screenBufferInfo); } else { var pairs = ColorTable.GetEnumerator(); while (pairs.MoveNext()) { var consoleColor = pairs.Key as ConsoleColor? ?? LanguagePrimitives.ConvertTo <ConsoleColor>(pairs.Key); var color = pairs.Value as RGBColor? ?? LanguagePrimitives.ConvertTo <RGBColor>(pairs.Value); SetColorHelper(consoleColor, color, ref screenBufferInfo); } } if (TextForegroundColor.HasValue) { screenBufferInfo.wAttributes = (short)((screenBufferInfo.wAttributes & 0xfff0) | (int)TextForegroundColor.Value); } if (TextBackgroundColor.HasValue) { screenBufferInfo.wAttributes = (short)((screenBufferInfo.wAttributes & 0xff0f) | (int)TextBackgroundColor.Value << 4); } if (PopupForegroundColor.HasValue) { screenBufferInfo.wPopupAttributes = (short)((screenBufferInfo.wPopupAttributes & 0xfff0) | (int)PopupForegroundColor.Value); } if (PopupBackgroundColor.HasValue) { screenBufferInfo.wPopupAttributes = (short)((screenBufferInfo.wPopupAttributes & 0xff0f) | (int)PopupBackgroundColor.Value << 4); } // conhost returns an off-by-one window size, so we must compensate screenBufferInfo.srWindow.Bottom += 1; screenBufferInfo.srWindow.Right += 1; NativeMethods.SetConsoleScreenBufferInfoEx(stdOutHandle, ref screenBufferInfo); }