Вывод power shell с цветом, перенаправленным в файл

I want to put in red some words to test a msg that i will deploy/activate when i connect remotely to a pc.
I have tried placing at the begining:

Set-PSReadLineOption -Colors @{ ContinuationPrompt = 'Red' }
powershell -WindowStyle hidden -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');...

It doesnt work.

And putting the function foregroundcolor at but gives me error.

powershell -ForegroundColor Red -WindowStyle hidden -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); ...

This is the code,the message pops and works well, i just want to put colour on the text.
I would like to put the words “please dont touch your keyboard or mouse” in red or if its not posible the whole text in red.

powershell -WindowStyle hidden -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('IT departament has connected to your PC please dont touch your keyboard or mouse, thank you','TEST/Message')}"

asked Aug 28, 2023 at 7:24

AALV8's user avatar

7 bronze badges

As far as I know, you can’t change the font color in MessageBox. However, you can use a warning icon, like so:

powershell -WindowStyle hidden -Command "& {
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
[System.Windows.Forms.MessageBox]::Show('IT department has connected to your PC please dont touch your keyboard or mouse, thank you','TEST/Message',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Stop)
}"

TEST/Message

answered Aug 28, 2023 at 8:43

Re1ter's user avatar

1 gold badge4 silver badges12 bronze badges

As u guys suggested i created a new window and centered it , im able to put the text in red but cant make it bigger or center it in the text box but it works.So solved.

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object System.Windows.Forms.Form
$Form.Width = 200
$Form.Height = 200
$StatisticsBox = New-Object System.Windows.Forms.RichTextBox
$StatisticsBox.Location = New-Object System.Drawing.Size(30, 30)
$StatisticsBox.Size = New-Object System.Drawing.Size(120, 100)
$StatisticsBox.MultiLine = $True
$StatisticsBox.ScrollBars = "Horizontal"
$StatisticsBox.ReadOnly = $True
$StatisticsBox.Font = "Lucida Console"
$StatisticsBox.BackColor = "White"
$Form.Controls.Add($StatisticsBox)
$StatisticsBox.SelectionColor = 'Red'
$StatisticsBox.Text = "`r`nSE HA CONECTADO EL DEPARTAMENTO DE INFORMÁTICA`r`n" + $StatisticsBox.AppendText("NO TOCAR RATON NI TECLADO GRACIAS") + "`r`n" +$StatisticsBox.Text
# Calculamos el centro de la pantalla.
$screenWidth = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
$screenHeight = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
$centerX = ($screenWidth - $Form.Width) / 2
$centerY = ($screenHeight - $Form.Height) / 2
# Ejecutamos la ventana al medio
$Form.StartPosition = 'Manual'
$Form.Location = New-Object System.Drawing.Point($centerX, $centerY)
[void]$Form.ShowDialog()
$Form.Dispose() 

answered Aug 29, 2023 at 7:17

:/>  Total Commander скачать бесплатно русская версия для Windows 10 64 bit торрент

AALV8's user avatar

7 bronze badges