Sunday, June 02, 2019

PowerShell 7 Is Here - Getting Started

Like many IT Pros, I’ve been waiting on the first builds of PowerShell 7. Late last week Steve Lee on the PowerShell team inside Microsoft published a road map to PowerShell 7. And on Friday I finally got access to the code! YEAH. It took some playing around with the code, but I now have a basic development environment up and working. And of course, there’s a script for that.
The environment for PowerShell 7, at least for me, includes downloading the latest build and installing Visual Studio Code as my main IDE. Here’s my getting started script:
# 1. Fix Execution polity then install latest versions of Nuget and PowershellGet
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
Install-PackageProvider Nuget -Force |
  Out-Null
Install-Module -Name PowerShellGet -Force –AllowClobber 


# 2. Setup C:\Foo to hold stuff. ignore the error if it already exists,

#    then set location to C:\Foo
New-Item -Path C:\Foo -ItemType Directory –EA 0
Set-Location -Path C:\Foo

# 3. Install PowerShell 7

#    For now, load the preview version.
#    Based on: https://www.thomasmaurer.ch/2019/03/how-to-install-and-update-powershell-6/
$URI = "https://aka.ms/install-powershell.ps1"
Invoke-RestMethod -Uri $URI |
  Out-File -FilePath C:\Foo\Install-PWSH7.ps1
C:\Foo\Install-PWSH7.ps1 -UseMSI -Preview -Quiet


# 4. Download and save Install-Vscode script from PSGallery

Save-Script -Name Install-VSCode -Path C:\Foo

# 5. Now run it and add in some popular VSCode Extensions

$Extensions = "Streetsidesoftware.code-spell-checker",
              "yzhang.markdown-all-in-one",
              "davidanson.vscode-markdownlint"
$InstallHT = @{
   BuildEdition = 'Stable'
   AdditionalExtensions = $Extensions
   LaunchWhenDone = $true}
.\Install-VSCode.ps1 @InstallHT 

# 6. Install WindowsCompatibility module

# the ServerManager module
Install-Module -Name WindowsCompatibility -Force

In step 1, I update the execution policy, and install the latest versions of the NuGet package provider and get the latest PowerShellGet module. Windows 10 ships with older versions of these tools so updating them is a good thing to do. With step 2, I create a  local folder, C:\Foo, which is where I put stuff.  Feel free to change either or both of these steps to suit your needs. IN step 3, I download and run a script to install PowerShell 7 on the local system.  The code here is a slightly more long-winded (but possibly more easily understandable) version of a one-liner posted by @Steve_MSFT. 
In step 4, I download a script that installs VSCode and in step 5, I run the script. This installs the latest stable version of VSCode along with three useful extensions. Adjust this list as appropriate.                 
Lastly, in step 6, I install the WIndowsCompatibility module – which is going to be useful in order to use PowerShell 7 to support a wider set of modules/cmdlets.  I plan to highlight this in coming blog articles.
Now that you have PowerShell 7 land VSCode, you need to set VSCode to a) use your colour scheme of choice then set the version of PowerShell you want VS Code. On my workstation, here’s how that looks:
So now that you have both PowerShell 7 and VS Code installed, it’s time to start getting used to the new version. My next post is going to be around installing AD, and the issues arising (along with solutions where possible).














No comments: