PowerShell on Linux: is it really working?
Yes. It is. From the moment that Microsoft announced this on the 8th of August all eyebrows were raised and a high level of curiosity has been sparked, especially now when Microsoft is leaning heavily towards linux and open source in general.
Now why is this interesting? Well, first of all because of Azure and because running code and scripts from a linux box can enable a lot of useful applications, like provisioning resources, configuration and auditing, which you were previously doing from a Windows Server Box.
In the same day that Microsoft made their announcement, Amazon announced their AWS toolkit for PowerShell.
Following all this enthusiasm came the practical part and, three days later, How-To-Geek came up with the practical installation steps on different flavors of Linux (including MAC OSx):
And because Azure is important and Azure Resource Manager is the way Microsoft turned classical Azure into a cloud oriented public cloud infrastructure, I wanted to see how the AzureRM module was working with Powershell.
So after installing Powershell (in Ubuntu or MacOS for example) following the above guide, you will notice that trying to install the AzureRM module will fail most of the time and also with different errors like:
InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
PackageManagementInstall-Package : No match was found for the specified search criteria and module name 'AzureRM'.
Could not compare "6.0.0-alpha" to "5.0".
Now independently of the error you get, the source issue is the same: there are no available sources for this Powershell version and even if you do find the AzureRM, some dependencies will fail.
Of course Microsoft will fix this in the next releases but, until then, here is the workaround, tested on Ubuntu 14.04 and MacOS 10.11.6. (on Ubuntu 16 does not work)
- Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2/ -ProviderName NuGet -ExcludeVersion -Destination $home/powershell/modules
- Import-Module $home/powershell/modules/AzureRM.Profile.NetCore.Preview
- Import-Module $home/powershell/modules/AzureRM.Resources.NetCore.Preview
- Import-Module $home/powershell/modules/AzureRM.NetCore.Preview
Note 1: Get-Module -ListAvailable AzureRM does not display the AzureRM, which means that if you exit Powershell, you will need to rerun the commands.
Note 2: Another issue will be that some commands don’t even exist. For example if you try to create a vnet-to-vnet VPC connection, you will find out that the commands for creating the vnet gateway or the connection are not present.
This happens because the modules available for AzureRM in the powershell for Linux are limited to these:
And therefore the available commands for new AzureRM resources are:
Which is considerably less that we would have expected, but don’t forget it is still an alpha release. Nevertheless you can start now testing this new Microsoft cloudy tool and post news and comments if you have a different behavior or comments.