Changing the PS to something different

Brass Contributor

My company has two different O365 tenants, and I go back and forth between the two in PS all the time.  As you can imagine it's easy to get the two mixed up.  

 

What I'm trying to find out is if there is a way to force the two to be distinct.  One thing I was thinking of is can I change the PS command prompt to say something else?  Like "Production" vs "Stage"?  Or change the color of the command prompt line to Red for Prod and Green for Stage?

 

I have an auto login script for each environment, and at the end of each script it flashes "You are in the Production Tenant" a bunch of times, but that only lasts until it scrolls up out of the buffer.

 

I can't be the only person to have this issue.  What do the rest of you do to keep track of which PS window is which?


Thanks in advance.

Ted

 

3 Replies

Yes. See about_Prompts. This will show you the basics. A quick search will find lots of examples.

Personally, I prefer to leave the prompt alone (as it's still useful for showing the working directory and such) and instead change the Title of the PowerShell console to reflect on the current tenant. Here's the code I'm using:


$Host.ui.RawUI.WindowTitle = "Connected as: $($cred.username)"

 

Just remember to update it after each connect/disconnect event.

Thank you very much for that reply. That was exactly what I was looking for.