ridicurious.com
Powershell

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.

PREREQUISITES : 

HOW IT WORKS :

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

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.

You’ll find all your local scripts updated

and so does your Secret GitHub Gist.

 

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

 

 

 

 

 

Related posts

PowerShell GUI : Releasing Multiple Stale IP's from DHCP Scope at once.

Prateek Singh
9 years ago

Mount the Azure drive on Local PowerShell Console

Prateek Singh
6 years ago

PowerShell to C# & back: Hello World Explained

Prateek Singh
4 years ago
Exit mobile version