#PowerShell Side by Side #ProTip

Today I’m going to share with you a little but simple tip to enable you to do more Side by Side testing of PowerShell v6 with you current installed version in a simpler and less error prone manner.

 

Firstly we will create a new environmental variable which we can do in a number of ways but I quite doing it this way  as its easy enough to script

Function Update-PS6Path {

       

        $PS6LatestPath = Get-ChildItem ‘C:\Program Files\PowerShell’ -Directory |

                         Sort-Object CreationTime -Descending |

                         Select-Object -ExpandProperty FullName -First 1

        [Environment]::SetEnvironmentVariable(“PS6”,$PS6LatestPath,“Machine”)

    }

 

This then means that to Launch PowerShell v6 you can do this in the console to run PowerShell v6 (the latest installed version anyway) and in this case we are passing some of the available arguements to the powershell.exe application as noted at https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help

& $env:ps6 -NoProfile -NoLogo -ScriptBlock { $PsVersionTable } -NoExit

So hopefully this little snippet will help you out in doing some more Side by Side testing as time goes on.

1 Small thing about running PowerShell Core and Windows PowerShell side by side on Windows

*Updated August 23rd 2016 as there was a change between 6.0.0.8 & 6.0.0.9 to PSModulePath that I had missed – I will be blogging about this in more detail in a future post but for now check the updated section at the bottom of this post! *

 

If your like me and you want to test out PowerShell Core on you Windows machines as well as other *nix machines then you may get caught out with this like I did in the upgrade from 6.0.0.8 to 6.0.0.9.

 

You can grab the MSI installer for 6.0.0.9 at https://github.com/PowerShell/PowerShell/releases/tag/v6.0.0-alpha.9  however do note that there are no Windows 7 or Windows 8 installers due to the requirements for WMF 4 to have been installed prior to WMF 5 as noted in this issue https://github.com/PowerShell/PowerShell/issues/1931 which links to this issue https://github.com/PowerShell/PowerShell/issues/1705
So lets get into the Side by Side stuff Smile

 

Once you’ve installed the MSI install you can run PowerShell 6.0.0.x alongside the Installed Version on your machine like so

 

PS-SBS

 

This is because PowerShell 6x installs in the following Location C:\Program Files\PowerShell\ and as you can see below I have installed 6.0.0.8 & 6.0.0.9 on my machine.

PS-SBS2

This also means that if we look in our Start Menu you can see the following new options

 

PS-SBS3

 

*Note* This will not change your default version of PowerShell from the one that is at C:\Windows\System32\WindowsPowerShell\v1.0\ so if your running Windows10 on the Insider Fast ring like me then it will run 5.1.1405.1000

 

To run one of these alpha versions you have to explicitly do so from the Start menu (or a desktop link if you create one) so you can be sure that this will not cause your any issues with day to day PowerShell use.

 

Hopefully that clears up any potential confusion!

 

In 6.0.0.8 the $profile Variable referenced the Windows PowerShell Documents location as can be seen below

PScore-6.0.0.8

 

Whereas in 6.0.0.9 we have a new location as shown below

PScore-6.0.0.9

 

So when we load 6.0.0.9 we wont get our profile to load as it doesn’t exist.

So that we can get our current profile to load in 6.0.0.9 we can do what we would normally do and just use New-Item like I’ve shown below

PScore-6.0.0.9-2

 

This seems only to have been needed in 6.0.0.8 & not 6.0.0.9 – as the default values in 6.0.0.9 for the PSModulePath are not what we have set in the ENV Variable and I’m not sure how this works but will dig in and post about this at a later date!.

 

Then next time we load 6.0.0.9 we will have a working profile but the issue is that this will now enable loading of all the modules that we have in our PSModulePath environmental variable.

 

. However we can get round this by 1 simple line in our Profile

If ($PSVersionTable.PSEdition -ne ‘Desktop’)
{ if ($IsWindows -eq $true)
{  $version = $host.UI.RawUI.WindowTitle.Split(‘_’)[1] ;
$env:PSModulePath = “C:\Program Files\PowerShell\$version\Modules” ;
Write-Output ‘Removed all but the shipped Core modules’
}
}

This is a Windows only forwards compatible inclusion in your profile & will only affect the local session of PowerShell that is running.

So you can be sure that this will work across your Windows Machines however ideally we will get some amendments to PSVersionTable as noted in https://github.com/PowerShell/PowerShell/issues/1997 & https://github.com/PowerShell/PowerShell/issues/1936 to be able to tell the OS easier and more dynamically.

 

The $IsWindows variable is only available in PSCore along with $IsOSX , $IsLinux & $IsCoreCLR so you cannot currently use them in the Full Version of PowerShell and currently I don’t think that you can build the full version of PowerShell from the Repository to a 6x version. However this may change in future.

So you can actually with 6.0.0.9 and above ignore the above section completely and comment that out of your profile (or delete it)

 

This is also a good example of the rate of change between the different alpha versions although I’ve checked the commit notes and cant see this change mentioned in a concise and easy to understand manner so I will feed this back to them to see if release notes can be improved in future.

My Opinion on Open Source PowerShell and what this means to the PowerShell community

If you’ve been under a rock the last few days (or for days/weeks/months depending on when your reading this blog post) then you would have missed that on Thursday August 18th 2016 –  Microsoft Open Sourced PowerShell!

Not only did they Open Source PowerShell they have released a Cross-Platform alpha version that can be installed on a variety of Linux Distros as well as a Mac OSX version.

 

You can read about it in more detail from the Jeffery Snover himself from over at https://azure.microsoft.com/en-us/blog/powershell-is-open-sourced-and-is-available-on-linux/

You can also read the PowerShell Teams blog (which has some great links too) on this at https://blogs.msdn.microsoft.com/powershell/2016/08/18/powershell-on-linux-and-open-source-2/

 

But what does this really mean to you, me, & all the other PowerSheller’s across the globe?

 

Firstly

 

  • Well done – you picked to learn a technology, which celebrates its 10 year old anniversary later this year (November 14th) and that was considered a “Windows only” tool and now it’s not this now means that you could start working with other platforms – increasing your value to your employer *cough maybe its time for that payrise*
  • PowerShell is likely to start to change even quicker (I’m speculating past the Server 2016 launch here)
  • If you don’t want to get involved and help with building PowerShell v6 (& fixing any bugs you find) then you can let this announcement pass you by a little and await an actual real release in the future

However if you do

 

  • You need to start learning some more new things and not just start learning PowerShell as there is now an even bigger ecosystem of tools that you need to learn to be really efficient and successful in IT going forward.
  • You need to learn how to work with source control and I will recommend git like I do to every one else. Check out https://help.github.com/articles/good-resources-for-learning-git-and-github/ for some resources but a google search will get you some others too.
  • You need to learn how to work with Github Issues and search and be able to file an issue that has enough information to be useful for the person reading it. Some of this is helped by Issue Templates but these don’t always capture all the possible required information so be prepared to be asked for more info.
  • You need to start attending User Groups & Conferences and train for your IT Future as the world of IT is undergoing a massive change and this isn’t going to stop anytime soon and if anything the rate of change is going to start getting quicker and quicker.

 

 

So where are we right now?

 

Currently the release of PowerShell to Github is an Alpha release – this means that it is not supported in any case for any production uses at all! Basically its out there for you to “kick the tyres” so to speak.

It also means that at least for now and the near future you may think that you have 2 places to raise issues. Github & UserVoice.

However The Guidance from the PowerShell team is this at present

Customers and Enterprise users should still raise these on UserVoice as this is still where issues relating to the PowerShell Engine that are contained within Windows Client and Server Systems including WMF releases should be raised.

Basically this means for issues that relate to anything PowerShell v5.1 and below should be raised on UserVoice.

My understanding of this is because these versions of PowerShell haven’t been released to Github (we have the changes that have occurred since PowerShell 5.1 was rolled up for WMF 5.1) so changes to them can only be done by the PowerShell team – plus we do need to remember that Server 2016 is still yet to RTM and the Source code for that will have been sealed in preparation for launch. So any fixes to the PowerShell engine included in Server 2016 or the RTM version of WMF 5.1 will come either by hotfixes or a recommendation to upgrade to a stable version of PowerShell 6 once released as we currently have alpha releases available on GitHub.

However For Developers and those that feel comfortable to do so then they can raise issues on Github.

This is where current guidance from the PowerShell team could easily bring a little confusion to some but we have to remember that this is new ground for the PowerShell Team so they will need to have some time to sort out how they work with the different streams. It is likely (& I’m just speculating here) that the team has an internal consolidated issue tracker that tracks UserVoice and all of the PowerShell Repo’s, however be on the look out for a blog post from the PowerShell team at https://blogs.msdn.microsoft.com/powershell in the next few weeks where they will be detailing how they interact with the community across these mediums.

 

So What does the future hold for PowerShell?

 

Over the course of the upcoming months we will see a number of further alpha releases as well as a stronger emphasis on making use of the PowerShell RFC Process for any changes to how the PowerShell Engine works. The PowerShell RFC Process can be found at https://github.com/PowerShell/PowerShell-RFC and there are a few new additions to this already from outside of the PowerShell Team.

 

But the interesting thing from this point on is that there will be more and more of the PowerShell Eco System open sourced including 1 module that I’ve been waiting to tear apart – PowerShellGet – which Jason Shirk confirmed is planned to happen in the future in this Issue https://github.com/PowerShell/PowerShell/issues/1979 – It is also worth noting that a number of the modules that we have inbox on Windows 10 Machines are not written by the PowerShell team so there is likely a chance that the module, cmdlet or function that you have ideas to improve (New-Item is one I’d like to see be a bit more intelligent with folder creation) may not be open sourced – however I think it is a matter of time before we see there be demand for these to be open sourced as well and there are already calls for other modules from other teams to be Open Sourced including the SQLServer module (was SQLPS) which shows where the ecosystem has been going for some time now.

 

Overall I’m incredibly proud to be working with such an amazing product that now has opened even more doors to me than what it had available to it before. You never know what the future will hold but now I have skill that can be used cross platform that means to me that the possibilities in the upcoming months & years of my IT Career are even more prosperous than they were last week.

 

If you haven’t yet picked up PowerShell I would seriously urge you to do so!

If your struggling on how to pick up this language and understand the benefits that it can bring you and are interested in learning more, here is a number of resources that you may find useful.

https://www.pluralsight.com/search?q=PowerShell&categories=course
https://stackoverflow.com/questions/tagged/powershell
https://powershell.org/
https://aka.ms/psslack
https://aka.ms/psdiscord
http://poshcode.org/
https://powershell.org/summit/
http://www.psconf.eu/
https://psday.uk/
https://www.meetup.com/pro/uk-devopscollective/
https://www.youtube.com/user/powershellorg/videos
https://www.youtube.com/channel/UCxgrI58XiKnDDByjhRJs5fg/videos
https://www.youtube.com/channel/UCplHMQDHTYH3wA7A1YcaVTw/videos
https://www.youtube.com/channel/UCnWPTrwSmO5xvjOiqqLTYpg/videos
https://mva.microsoft.com/training-topics/powershell#!jobf=IT%20Pros&lang=1033
https://channel9.msdn.com/Search?term=PowerShell&lang-en=true
https://www.powershellgallery.com/
https://github.com/PowerShell?utf8=%E2%9C%93&q=DSC&type=&language=

I’m looking forward to seeing how the future pans out with xplat PowerShell – what are you looking forward to the most with this?