In preparation for my latest course in the AWS Networking Deep Dive series, I wanted to install PowerShell Core on an Amazon Linux instance to test out cross-platform compatibility for some scripts.
Specifically, I wanted to see if I could use methods in the System.Net.Dns class to perform name resolution. The dnsclient PowerShell module provides some cmdlets for this very purpose, but that module is Windows-only, and I needed something that would work on across different platforms.
To my surprise, it wasn’t as easy as just running sudo yum -y install powershell. Fortunately, it wasn’t as difficult as building from source. Here’s what I did:
Install the dependencies#
sudo yum install -y curl libunwind libicu libcurl openssl libuuid.x86_64Download the installation script#
This script just fetches the tarball and extracts it to /opt/microsoft/powershell
wget https://raw.githubusercontent.com/PowerShell/PowerShell/master/docker/InstallTarballPackage.shSet the script to be executable#
chmod +x InstallTarballPackage.shRun the script, specifying the PowerShell version (6.0.1) and package tarball as the arguments:
sudo ./InstallTarballPackage.sh 6.0.1 powershell-6.0.1-linux-x64.tar.gzIf you want to install a specific version (like the latest), then refer to the releases on the PowerShell repo.
Run PowerShell!#
The command is pwsh, as in “Present Working SHell” (clever points). Be sure to use sudo, as it does require root privileges:
sudo pwshGet Your .NET On#
The whole point of this exercise was to see if I could use .NET to perform DNS name resolution without any of the cmdlets in the Windows-only dnsclient module. Did it work? Let’s see.
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/ec2-user> [System.Net.Dns]::GetHostAddresses("benpiper.com").IPAddressToString
52.205.213.4Yes indeed! Of course, I can still use the usual PowerShell tricks to extract just the data I want:
PS /home/ec2-user> [System.Net.Dns]::GetHostByName("pluralsight.com") | Select-Object AddressList
AddressList
-----------
{54.213.174.143, 35.164.44.204, 52.39.160.43}I can also drill down to pick out just the first IP address in the list:
PS /home/ec2-user> ([System.Net.Dns]::GetHostByName("pluralsight.com")).AddressList[0].IpAddressToString
54.213.174.143Run it again, and I get a different address:
PS /home/ec2-user> ([System.Net.Dns]::GetHostByName("pluralsight.com")).AddressList[0].IpAddressToString
52.39.160.43Looks like round-robin DNS! But will this command work cross-platform? Let’s try it on my Windows 10 machine:
PS C:\Users\admin> ([System.Net.Dns]::GetHostByName("pluralsight.com")).AddressList[0].IpAddressToString
35.164.44.204Yes! This is exactly why I chose PowerShell. The same command that works on Linux also works on Windows, which makes it perfect for an OS-agnostic course.

