Another blog on customizing the PowerShell console? Really?
Yes. This is actually what I use on a day-to-day basis as a consultant managing many projects at once. I find that I'm usually running various PowerShell sessions concurrently and having to keep which one is which can be difficult without having to stop and check which server or Office 365 tenant I'm connect to, or what type of activity I'm performing.
To help keep this straight, I put a few functions in my PowerShell profile for my day-to-day use.
To edit your PowerShell Profile, you can type notepad $PROFILE from a PowerShell prompt. If you've never modified or created one, you'll need to create the directory first using New-Item $HOME\Documents\WIndowsPowerShell -Force.
My PowerShell Profile looks like this:
Import-Module MSOnline
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
CD \Scripts
# Set Console Settings
Function Console($Background,$ForeGround,$Title)
{
Clear-Host
$console = $host.UI.RawUI
$console.BackGroundColor = $Background
$console.ForeGroundColor = $Foreground
$console.WindowTitle = $Title
cls
}
# Office 365 Logon
Function o365Logon()
{
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $UserCredential
$LyncSession = New-CSOnlineSession -Credential $UserCredential
Import-PSSession $LyncSession
}
What the main functions do:
Function Console($Background,$Foreground,$Title)is a function declaration that allows me to easily change the foreground, background, and window title of the current PowerShell window. To change and of those settings, after launching my PowerShell window with this profile, I simply type Console -ForegroundColor <color> -BackgroundColor <color> -Title <what I want in the title bar>.
Function o365Logon calls the a series of commands to connect to an Office 365 tenant (prompting for credentials, importing Exchange and Lync/Skype sessions).