The PowerShell ISE was first shipped with PowerShell 2.0 (November 2006), and greatly improved in PowerShell 3.0 (August 2012), with the PowerShell Tabs, the Show-Command Add-on and the snippets (CTRL+J). But since then, it pretty much stayed the same.

Fast forward to May 2017, David Wilson from the PowerShell team announced (amongst other things) that:

“The PowerShell ISE has been the official editor for PowerShell throughout most of the history of Windows PowerShell. Now with the advent of the cross-platform PowerShell Core, we need a new official editor that’s available across all supported OS platforms and versions. Visual Studio Code is now that editor and the majority of our effort will be focused there.”

This means that if haven’t already, it’s time to get acquainted with Visual Studio Code (aka VSCode).

There are lots of blogs and tutorials out there, describing the VSCode installation process and usage, with or without the PowerShell extension, but none are discussing the installation of both in an “offline” environment.
This post is an attempt to bridge that gap, and explain the steps required to prepare your PowerShell development environment in case your machine is disconnected from the internet and you can’t directly install everything.

Step 1 – Download VSCode:

The installation package can be downloaded from: https://code.visualstudio.com/Download

Direct link for Windows x64: https://go.microsoft.com/fwlink/?Linkid=852157

Step 2 – Download the PowerShell extension:

The PowerShell extension can be downloaded from the extensions repository:
https://marketplace.visualstudio.com

Direct link for version 1.5.1:
https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode/vsextensions/PowerShell/1.5.1/vspackage

Step 3 – Copy the files to the “offline” machine

Step 4 – Install:

The VSCode installation is pretty much straight forward. “Next, Next, Next… Install”.
The PowerShell extension (vsix) installation is done manually, from the VSCode itself:

vscode-vsix-install

  1. Open the extensions sidebar by clicking the last icon on the bottom left
  2. Click on the ellipsis (…) in the right upper corner
  3. Choose Install from vsix
  4. Browse to the vsix you previously downloaded, and that’s it. Maybe*

* There’s currently a problem installing the PowerShell extension version 1.5.1 on VSCode 1.19.x.
But don’t worry, there’s a workaround:
Since the vsix is actually a zip file, you just need to extract and copy the contents of the extension folder to $env:userprofile.vscodeextensions{Name_And_Version_Of_The_Extension}

To automate it:


$vsixFile = 'C:Tempms-vscode.PowerShell.1.5.1.vsix'
$tmp = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([guid]::NewGuid().GUID)
$zipFile = Rename-Item -Path $vsixFile -NewName ($vsixFile -replace '.vsix', '.zip') -PassThru | Select-Object -Expand FullName
Expand-Archive -Path $zipFile -DestinationPath $tmp
Copy-Item -Path "$tmpextension" -Destination ('{0}.vscodeextensions{1}' -f $env:USERPROFILE, (Get-Item -Path $zipFile).BaseName) -Recurse -Force
Remove-Item -Path $tmp -Recurse -Force

For more information and resources on writing PowerShell with VSCode, check out these:

Transitioning from PowerShell ISE to VS Code:
https://channel9.msdn.com/Blogs/MVP-Azure/Transitioning-from-PowerShell-ISE-to-VS-Code

Experimenting with VSCode instead of the ISE:
https://voiceofthedba.com/2017/09/18/experimenting-with-vscode-instead-of-the-ise/

Debugging PowerShell script in Visual Studio Code:
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/

HTH,
Martin.

Advertisements