locked
Powershell Backround Colours on remote servers RRS feed

  • Question

  • So my search-fu is helping me much at the moment. Essentially a few days ago I had a rather embarrassing incident. I was logged onto one of our production servers with powershell troubleshooting an issue. I fixed the issue and forgot to exit out of the remote powershell session.

    I got to the end of the day and as normal started closing out of applications and switched to powershell to shutdown my laptop ready to take it home with me.

    Bet you can't guess what happened next....

    So my question is how can I add a backround colour to my remote powershell sessions to quickly and easily identify them e.g have my local console black and the remote console for all servers be RED. Ideally this would be done with something in my powershell profile rather than creating a new profile on each server as there are a lot of servers in the domains.

    Has anyone done this or got an idea on how to do it?

    • Moved by Bill_Stewart Tuesday, June 16, 2015 8:39 PM Abandoned
    Tuesday, April 21, 2015 4:16 PM

All replies

  • Hi,

    Below link covers almost everything that you need.

    PowerShell Basics: Console Configuration

    Only limitation would be when you are not in Remote but local still the profile coloring won't change.

    There is something called cmdlet extension agent \Scripting Agent for Exchange Server Shell, which allows you to customize cmdlets actions.

    Other option would be like calling the remote sessions using VBA or VBS to call the PS with custom scripts(RawUI BG Color and Enter-PSSession)

    VBA calls a command to run PS1:

    Call Shell("powershell -file ""C:\scripts\RemoteServer.ps1""", vbMaximizedFocus)

    This will allow you to have normal local sessions and colored remote sessions.

    Another Option would be using the environment information on Start to generate the session:

    if ($host.UI.RawUI.WindowTitle -match “Administrator”) {$host.UI.RawUI.BackgroundColor = “DarkRed”; $Host.UI.RawUI.ForegroundColor = “White”}
    You can modify the if condition to match your servername -like "Server*" etc.

    References:

    Run Script from a remote connection

    Get-Host


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Wednesday, April 29, 2015 8:05 AM
  • some other options:

    get in the habit of using -confirm: restart-computer -confirm

    check the target, and then hit Y or N

    or make a reboot function

    function reboot-computer {

    if ($env:COMPUTERNAME -ne "mycomputername") {write-warning "Exit the remote session first!"}

    else {restart-computer}

    }

    Wednesday, April 29, 2015 6:16 PM
  • Hi,

    Any updates.


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    Monday, May 4, 2015 11:53 AM