#PowerShell Side by Side #ProTip

Ryan YatesConsultant

Just a dude in his 30's doing things in Tech & trying to break the stigma's around talking about Mental Health

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.