powershelldeploymentsystem-administration

Put colour on a popup/message in powershell


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')}"

Solution

  • 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