Consistent $Profile across All PowerShell Hosts and a Backup on GitHub


Hello Friends,

I work or on multiple PowerShell editors and multiple computers (Home and Office) and I heavily rely on my PowerShell Profile for stuff like API Keys, Environment variables, useful Functions and Aliases.

Switching to a new machine or a different Editor, I find myself help less ( Not this much like it sounds here 😛 ) . Since I keep on adding Functions to my $Profile but its not there on other editors until I copy-paste the profile, moreover  all newly added Functions are absent from on a different computer.

PURPOSE : 

  1. Replicate any changes to all my PowerShell $profiles ( Tested with ISE, Console and Visual Studio 2015 hosts) based on the latest “LastWriteTime” property of Profile.ps1.
  2. Also updates a copy to GitHub,  making my profile available over the internet.  Like in case I want the changes\updates Done on my office computer’s Profile at my PC at home.I can easily download my profile and we’re good to go.
    • Makes a Secret Copy (NOT PUBLIC), so that your credentials, API Keys (All your Secret stuff) is not visible to everyone and can be only downloaded when you login using your GitHub Credentials.
    • While updating the GitHub gist the script adds a description note to the gist with TimeStamp and the Machine name from where the Profile was updated.git
    • GitHub gist is named as Hostname_Profile.ps1 so that you can differentiate between profiles updated from multiple machines.git

PREREQUISITES : 

  • You’ll need to Convert your GitHub password into encrypted plain text like below  and copy the resultant string as value to variable $EncryptedPasswordString in the script.Pass

    This Encrypted string will work only on the machine where it was generated

  •  Also insert your Github Username at the place highlighted in the below screenshotstring

HOW IT WORKS :

To make it work is a 3 step process and below is a screenshot with the steps involved –

profile

HOW TO RUN IT : 

Get the script from HERE and Copy-Paste in your  PowerShell $Profile. Make sure you meet the Prerequisites mentioned earlier in this blog post.

Save and run your Profile for the initial setup. It will copy the updated Profile to all other profiles and will keep checking for updated versions of profiles next time you open any Powershell editor.

vs

You’ll find all your local scripts updated

filewritetime

and so does your Secret GitHub Gist.

git

 

NOTE : 

This case is specific when you want all your PowerShell hosts to Load same profile.

There may be scenarios where this script doesn’t work, I’ve tested this with Powershell Console, ISE and VisualStudio PoshTools host. Please add directories or FileName you want to update depending PowerShell hosts installed on your machine.

Thanks for reading!
@SinghPrateik

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s