How to Customize your PowerShell Profile?

Customize your PowerShell Profile

How to customize your PowerShell Profile to load all the custom created function at the PowerShell startup

 

As an office 365 administrator I have to connect to office 365 and MSOL pretty frequently to do my daily jobs, I am a lazy guy so it was tiring for me to copy and paste the those command all the time and typing password every time so to make my work easy I wrote this power shell script which do this task form easy, I customize the my PowerShell startup and added useful function.

Below is the code you can use to customize your PowerShell home or you can use the my .Bat script installation package I wrote which install will install this package on your system I also include office 365 command box I wrote which we will cover later in this post.

How to customize your PowerShell home like below?

 

 

1.       Go to  “%userprofile%\Documents\” and create folder WindowsPowershell

2.       Next inside this folder create ps1 file name it as “Microsoft.PowerShell_profile.ps1

3.       Next here is to logic of the powershell startup, When powershell starts its check for any ps1 to be run in the user home profile “Documents\WindowsPowershell” folder so in this script we will write a function “Prompt” which will do the magic for us.

4.       Next you can either write your own code and function or take an idea from the below code of mine or simply download the package and run the bat file it will install automatically.

 

 

function Prompt

{

    $id = 1

    $historyItem = Get-History -Count 1

    if($historyItem)

    {

       $id = $historyItem.Id + 1

    }

    Write-Host -F Cyan "`n[$(Get-Location)]"

    Write-Host -NoNewLine "PS:$id > " -f Red

    $host.UI.RawUI.WindowTitle = "$(Get-Location)"

    "`b"

}

#below you can mention any Powreshell module or your function script to be imported

. “c:\example\test.ps1”

# Below is the screen I designed for myself, you can designed similar one for yourself they why you like it

write-host "

######################################################################

                

  YOU ARE IN A CUSTOMIZED WINDOWS POWERSHELL SESSION FOR O365

 

                Connect365        = Connect to O365 (With Saved Credential)

                Connect                               = Connect to O365 (WithOut Saving Credential)

                Disconnect365   = Disconnect from O365

                ExportCred         = Save New Credential

                O365                      = Start 365 Junk Box

                ConnectMSOL     = Connect Microsoft Online for O365

                                                                               

                                                                                    Designed by: Sunil Chauhan

######################################################################

                                " -f DarkGray

 

 

Note: Above code does not have function and scripts reference to functions displayed in above sample script Screen,

If you wants to use the same screen designed as me you need to download the package and modify it accordingly.

 

What is included in My Package,

1.       Automate Logon process for Powershell

2.       Office365 JunkBox ( this include most of the automation tasks, for more details on this check my blog)

3.       Zip support Module (Mostly used in reporting to zip file before sending them via email)

 

Download complete Package Here

                Next we will learn how to Automate Login process for Powershell,  please check my next post on the same.

Comments