How To Use the .Net Core With PowerShell One-Click Image
This article exists for historical reference and is no longer maintained.
The .Net Core and PowerShell on Ubuntu is no longer offered.
.Net is the go-to platform for Windows Developers. It is used to write desktop, command-line, mobile, and web applications using a standard set of libraries and frameworks called .Net Core. PowerShell is a task automation language originally written to manage Windows systems that leverages elements of .Net to write more powerful scripts. While applications are generally written in .Net, PowerShell is a scripting language.
DigitalOcean provides a One-click image for .Net Core and PowerShell on Ubuntu 16.04 so you can get started using these technologies quickly. In this tutorial, you'll create a new Droplet that runs PowerShell, and you'll test it out by creating and running a small PowerShell script.
Both .Net Core and PowerShell for Linux are listed as being in preview at the time this article was written. As a result, the .Net/PowerShell image is targeted at developers who need a Linux environment that runs .Net Core or PowerShell for experimentation, development, and testing.
WARNINGS AND DISCLAIMERS
- These images are considered PREVIEW IMAGES.
- Production use of this image is strongly discouraged.
- DigitalOcean support is unable to offer support for the .Net Core or PowerShell components.
- DigitalOcean may elect to remove this image with a 14-day deprecation notice to active users via email.
In addition to the features available on a regular Ubuntu 16.04 Droplet, the .Net/PowerShell image includes:
- The .Net Core
Additionally, in order to improve security the following components are included:
iptables: A standard firewall included in most Linux distributions by default.
ufw: A front-end to
iptablesthat allows for easy management of a firewall.
Another notable difference is that the default shell for the
root user has been set to PowerShell.
Create Your .Net/PowerShell Droplet
The easiest way to create a Droplet with support for .Net Core and PowerShell is through the DigitalOcean user interface. Log into your account and coose Create Droplet.
In the Choose an image section, click the One-click apps tab and select the .Net Core w/ PowerShell on Ubuntu 16.04 image.
Next, select a size for your Droplet
Then select your desired region:
Next, select any additional settings you'd like, such as private networking, IPv6 support, or backups.
Then select which SSH keys, if any, you want to use to access the Droplet. When you're ready, click the Create Droplet button.
Finally, select a hostname for your new Droplet. You may accept the default name or enter your own:
Once your Droplet has been created, you can access it by connecting to your Droplet as
root via SSH, using the IP address displayed next to your new Droplet.
Access the Droplet Via SSH
Now that your new Droplet is created, you can log in using SSH.
Open a terminal on your computer and execute this command, using the IP address associated with your Droplet:
If you haven't used SSH before, or are using PuTTY on Windows, you may want to refer to this tutorial for more details: How To Connect To Your Droplet with SSH.
If you are prompted for a password, enter the password that was emailed to you when the Droplet was created and follow the on-screen prompts to replace your temporary password. Alternatively, if you set up the Droplet with SSH keys, the keys will be used for authentication instead.
Once you log in, you'll be presented with the PowerShell prompt:
OutputPowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS /root>
Note: PowerShell includes command-line completion features. As a result, you may experience some flickering as you type when connected via SSH. This is caused by PowerShell refreshing the screen and is a known issue.
Now you can test out the environment.
Run a PowerShell Script
You now have a Linux environment that supports running PowerShell scripts and some .Net applications, Let's write a quick PowerShell script and make sure we can run it.
Create a new file called
Hello.ps1 with the
nano text editor:
- nano Hello.ps1
Add the following code to the file:
# A simple "Hello World" program in PowerShell Write-Host 'Hello World!' Write-Host "Good-bye World! `n"
Save the file and exit by pressing
CTRL-X, followed by
Y, followed by the
Now, execute the script:
You'll see the following output in your terminal:
OutputHello World! Good-bye World!
While that was a fairly simple script, it demonstrates that your Droplet can run PowerShell scripts successfully.
Warning: We're just testing things out in this tutorial. But if you were doing this for a production environment, you should follow our Initial Server Setup guide to give
sudo privileges to a non-root user, lock down the
root login, and take other steps to make your VPS ready for production.
Now that you have an environment configured for .Net and PowerShell, you can continue experimenting with projects of your own. Start with the following tutorials from Microsoft: