Written by 7:31 am Microsoft, Microsoft Azure, PowerShell, Visual Studio, Visual Studio Code • 4 Comments

Write PowerShell Online using Visual Studio Codespaces

Write PowerShell Code Online in a web browser using Visual Studio Codespaces

Last week the Visual Studio Services team announced a new service called Visual Studio Codespaces. Visual Studio Codespaces allows you to do cloud-hosted development for wherever you’re working. While the new services support many different programming and scripting languages, it also supports PowerShell. In this blog post, I am going to show you how you can write PowerShell code online in a web browser using Visual Studio Codespaces.

What is Visual Studio Codespaces

As mentioned, Visual Studio Codespaces (earlier known as Visual Studio Online) are cloud-hosted development environments, which are accessible from everywhere. I don’t want to go too deep into what Visual Studio Codespaces are since there are already great resources out there. However, I want to quickly give you an overview of the basics of Visual Studio Code spaces and how you can use them to write PowerShell code.

Visual Studio Codespaces gives you access to development machines, which can be cloud-hosted or self-hosted.

  • Cloud-hosted machines are machines running in the Microsoft Cloud, and you can take advantage of the power of that machine. In this case, you can use the web browser or Visual Studio Code to access that Codespace.
  • Self-hosted machines can be computers in your home, company, installed in the cloud using Azure VMs, or everywhere. Again, here you can use a remote machine using a web browser or VS Code to access that code space remotely.
Visual Studio Codespaces Overview

Visual Studio Codespaces Overview

This now allows you to have a powerful development environment that you can access and run from anywhere. I think that is pretty cool!

You can read more about the introduction of Visual Studio Codespaces here.

Set up a Visual Studio Codespace

To set up a Visual Studio Codespace, you simply go to online.visualstudio.com and get started. Depending on if you have used it before, you will need to create a new billing plan first.

Create Billing Plan

Create Billing Plan

After that, you can create your Codespace. You can also choose between different sizes or instance types, depending on if you need Windows or Linux, or how powerful your instance needs to be.

Create Visual Studio Codespace

Create Visual Studio Codespace

After a while, your cloud-hosted Codespace will be ready for you to use.

Visual Studio Codespaces

Visual Studio Codespaces

Write PowerShell Code Online in a web browser using Visual Studio Codespaces

Okay, now we have a cloud-hosted Visual Studio Codespaces setup, and we can now add the PowerShell Visual Studio Code extension, as we would do this with a local installation of VS Code.

Visual Studio Codespaces PowerShell Extensions

Visual Studio Codespaces PowerShell Extensions

Depending on the instance type you run, you can run Windows PowerShell 5.1 and PowerShell 7. You can even use the PowerShell ISE mode from VS Code.

PowerShell ISE Mode Visual Studio Codespaces

PowerShell ISE Mode Visual Studio Codespaces

You can also connect to the Codespace directly from Visual Studio Code (VS Code). So you don’t necessarily need to use a web browser.

Connected Visual Studio Codespace to VS Code

Connected Visual Studio Codespace to VS Code

Add a self-hosted codespace

If you want to add a self-hosed codespace (for example your work machine), you can easily do that from VS Code.

Self-hosted Codespaces

Self-hosted Codespaces

Now you can basically use your local machine to write PowerShell code with Visual Studio Codespace from anywhere.

Edit PowerShell scripts remote online using Visual Studio Codespaces

Edit PowerShell scripts remote online using Visual Studio Codespaces

Conclusion

I hope this gives you a quick overview of how you can write PowerShell code online in a web browser using Visual Studio Codespaces. You can also take advantage of many other VS Code extensions like the Azure extension for Cloud Shell, the Azure Virtual Machine extension, any many more.

You can simply try out Visual Studio Codespaces here.

If you have any question feel free to leave a comment.

Tags: , , , , , , , , , , , , , , Last modified: May 4, 2020
Close Search Window
Close