Azure CLI vs Powershell?
Asked Answered
F

12

86

Not precisely able to understand the merit of Azure CLI on Windows environment.

Is it targetted for the audience who want to manage Azure IAAS from Linux environment?

I thought Powershell core is going to be the way for non-Windows admins. Is PowerShell Core not going to be ported to well on all platforms, to serve the cross-platform audience?

In a nutshell, is it worth learning Azure CLI?

Future answered 9/8, 2017 at 8:6 Comment(2)
Basically yes, its targeted at linux guys. powershell core is available on linux and some modules ported already and working, obviously as time passes all the modules will be ported to core as full .net version of powershell is not going to happen.Hyden
There is a nice summary about Azure related command line tools here, that also included in the answer down below.Irs
O
55

Azure CLI is a PowerShell-like-tool available for all platforms. You can use the same commands no matter what platform you use: Windows, Linux or Mac.

Now, there are two version Azure CLI. The Azure CLI 1.0 was written with Node.js to achieve cross-platform capabilities, and the new Azure CLI 2.0 is written in Python to offer better cross-platform capabilities. Both are Open Source and available on Github. However, for now, only certain PowerShell cmdlets support use on Linux.

Is it targetted for the audience who want to manage Azure IAAS from Linux environment?

I think the answer is yes. For a Linux or Mac developer, I think they more likely to use Azure CLI.

Olympe answered 9/8, 2017 at 8:52 Comment(2)
Note there is now an Azure PowerShell module that you can install for PowerShell Core, which is a cross-platform version of PowerShell that runs on Windows, Linux or macOS.Highsmith
I'm also pretty sure there are some Azure Powershell commands that aren't present in CLI, but i can't think of it specifically atm. I am using both in Powershell Core on a MPB but I really prefer the CLI as it makes powershell scripts cleaner to look at. IMHO.Luncheonette
G
43

Both, Azure CLI and the PowerShell package use the REST API of Azure.

As one of our Microsoft contacts said: Use whatever you like and you prefer.

There are some pros for Azure CLI:

  1. Open Source - which has many advantages. It might be developing faster in the future. You can view what is really in the Code, the community might or will be bigger, and so on.
  2. Azure CLI can be used with Groovy, Python, Ruby or any other scripting language. It is easier to get good developers for this languages than an experienced PowerShell developer. For example: I took Groovy because of Java. It is easier to use this combination then learning PowerShell scripting....

Currently there is 1 really big positive for PowerShell: there is a huge repository of PowerShell script examples for Azure. BUT: often you have to do it on your own to fit your requirements - therefore an example might be a good starting point - sometimes it is easier to begin from scratch.

My recommendation would be: Use Azure CLI --> For Scripting use the language your company is familiar with.

Gaye answered 2/12, 2017 at 7:36 Comment(7)
Azure PowerShell is also open-source :)Lehr
Haha 'whichever I prefer'! I have no clue! I just want one!Baptista
There're a lot of feature not available on CLI ( datafactory for example)Paratyphoid
The real biggest benefit of Powershell is that it operates on objects, not on strings. Therefore it's really easy to work with output of commands: $t = Get-AzEventGridTopic ... ; $endpoint = $t.Endpoint. With Azure CLI you would have to parse strings for that.Malleable
@Monsignor: Thats actually not right.... depents on the script language you are using. Every language has its advantages and disadvantages. Since you can also get a JSON response: most languages give you an object like access on JSON. So your pro for powershell also fits for azure CLI.Gaye
never heard of Groovy. no shortage of powershell devsDogcart
@Malleable That benefit is equaled with $t = (az {your options} | ConvertFrom-Json). That is more an argument for bash VS. pwsh.Irs
J
32

Just wanted to add my experience with both Azure Cli and Az PowerShell.

As per 2019, both are cross-platform so it should only be a language/syntax preference but with Azure Cli all/most commands are idempotent.

I've ended up replacing all my ARM Templates with Azure Cli scripts as it is less verbose and easy to read.

With Az Powershell, you still need to check if the resource exists before creating it otherwise it will throw an exception so scripts can become very complicated for no reason.

We're using both Azure Cli and Az Powershell with Azure DevOps. Azure Cli command can now be executed from bash (Linux) or bat (Windows) scripts. So it is not optimum... (EDIT 2020 You can now run Azure CLI using Powershell scripts as well)

  • We deploy resources with Azure Cli because it is easy to read and commands are idempotent.
  • For complex scripting I prefer using PowerShell as there are a lot of useful language features.

EDIT 2021

With the new Azure Bicep, I've started going back to "ARM type" deployment: Bicep is really easy to use if you understand ARM template and stay readable even with complex deployments.

In addition to Az CLI (Powershell core) it handles most of the scripting i need to do.

Johan answered 10/3, 2019 at 3:30 Comment(8)
I realize you are free to do whatever you like in your own environment. However, it is important to say that "Replace ARM Templates with CLI Scripts" is NOT Best Practice.Brahmanism
Azure CLI commands can be used in Powershell scripts as well.Threephase
Yeah it could, I am using Azure Devops and it is hard to mix powershell and cli command together ?Johan
@JerryNixon-MSFT, you're right, My feeling is based on your engineer skills you better let them choose. ARM is declarative and have all the latest feature first. For example while deploying API Management we used ARM as it is much more easier.Johan
@JerryNixon-MSFT Could you elaborate or point to an article/blog post on why CLI is not "best practice" ?Busby
I find that az can do more then Powershell. Fx. "az resource show" can show much more details like createdTime for an Azure resource, where the same PowerShell command Get-AzResource doesn't give such detailed information.Steelwork
I created some powershell using the cli, but when I wanted to run this in DevOps pipeline I learned that this combo is not something that is automatically available. Very confusing having these 2 options. Has this been fixed yet, to allow you to choose whatever combo you like in your DevOps pipeline?Dalliance
Azure Bicep enters the room...Audriaaudrie
I
14

PowerShell has some significant advantages over CLI:

  • PowerShell is a language of Azure Functions. So you can easily write a module or code and push it to a secured Azure Function. CLI is not a supported language.
  • Same goes for Azure Automation Runbooks, whereas CLI is not a supported language.
  • If you want to orchestrate a hybrid workload covering on premise and cloud, i.e. deploy a Service to a Windows Server and then deploy an endpoint in Azure for it to interact with, PowerShell can but CLI can't (and I would surprised if it did).
  • If you want to invest in one language that can call legacy Modules for management, PowerShell can but CLI can't.
  • If you want to create your own DLL in C# or any other language and incorporate that into your scripts. I've had to reverse engineer DLLs and wrap them in PowerShell to incorporate into orchestrations.
  • I've had significantly more success extending DevOps pipelines with PowerShell than CLI.
  • PowerShell has very good multithreaded workload support for scenarios such as Azure unit and smoke testing and large Azure parallel deployments (beyond DevOps parallel tasks which get clunky). TBH, I am not aware of native multithreading in Azure CLI.
  • I can develop a module, use it in all the above scenarios and then give it to an end client; TBH, I don't believe I can do that for CLI (create a module, digitally sign it and then nuget feed distro).

There is almost nothing I've not scripted in PowerShell, whereas with CLI I can do something but not others. My PowerShell skills have kept relevant for over 10 years where I've been doing enterprise SharePoint, Dynamics, now Office and Azure... so I am biased.

Improvise answered 28/10, 2020 at 2:42 Comment(1)
We can easily use Azure CLI from PowerShell. IMO it's not a factor for choosing Azure CLI tool vs Azure PowerShell module. You are right about bash is not a supported language for Azure Functions. I would also highlight that PowerShell is really powerful cross platform scripting language with object level pipe processing.Irs
D
5

Powershell was not available in non-Windows platform prior to 2018. Staring Jan 2018, Powershell is available in MacOS and Linux platforms.

Installation instructions for Powershell on MacOS or Linux is available here

Deaminate answered 4/4, 2018 at 2:47 Comment(0)
M
5

PowerShell is Open Source too. Microsoft have just released PowerShell Azure Az module (Dec 2018), which uses .Net core. So it runs on Linux,Mac OS and Windows. Azure CLI is still there for Linux developers, if preferred.

Marsh answered 26/1, 2019 at 20:31 Comment(0)
A
3

In a nutshell, is it worth learning Azure CLI?

I've noticed when doing the MS Azure training (AZ-900 fundamentals and AZ-303 Azure Architect) is that the exercises are done in Azure CLI. Granted, they're all "copy and paste this code" but it seems that MS are favouring CLI over PowerShell, at least for training purposes.

UPDATE: I recently had a lot of trouble with Azure CLI behind a proxy. PowerShell did NOT have any issues. As someone used to PowerShell, the CLI is kinda clunky and dumb. That said, Terraform requires Azure CLI so that may be a good enough reason to consider it.

Angulo answered 17/11, 2020 at 11:29 Comment(0)
H
3

Since this is a frequently asked question in the Community, an article covering the similarities, differences and nuances between the various Azure command-line options was added to the documentation recently: Choose the right Azure command-line tool. This doc should answer most of your questions as well.

When it comes to managing Azure, you have many options. Although Azure CLI, Azure PowerShell, and Azure Cloud Shell have overlapping functionality, each operates differently, and the language is sometimes confused with the environment.

Azure CLI vs Azure PowerShell: Azure CLI and Azure PowerShell are command-line tools that enable you to create and manage Azure resources. While both are cross-platform and installable on Windows, macOS, and Linux, Azure CLI runs in Windows PowerShell, Cmd, or Bash and other Unix shells, whereas Azure PowerShell requires Windows PowerShell or PowerShell.

Different Shell Environments: Windows PowerShell, PowerShell, Cmd, and Bash are shell environments. Your shell environment not only determines which tools you can use but also changes your command-line experience.

Shell Environment | Azure CLI | Azure PowerShell |
------------------|-----------|------------------|
Cmd               | Yes       |                  |
Bash              | Yes       |                  |
Windows PowerShell| Yes       | Yes              |
PowerShell        | Yes       | Yes              |

Using an Azure command-line tool isn't always necessary, but it's a useful skill to have. Here are a few key factors to remember when choosing a command-line tool:

  • When picking the right tool, consider your past experience and current work environment.
  • Azure CLI syntax is similar to that of Bash scripting. If you work primarily with Linux systems, Azure CLI feels more natural.
  • Azure PowerShell is a PowerShell module. If you work primarily with Windows systems, Azure PowerShell is a natural fit. Commands follow a verb-noun naming scheme and data is returned as objects.
  • Keep in mind that feature parity for Azure services doesn't always exist between Azure CLI and Azure PowerShell.
  • Choose the tool that uses your experience and shortens your learning curve. Use a different tool when it makes sense to do so.
Hesson answered 16/12, 2021 at 7:42 Comment(0)
M
1

Not necessary you'll use the Azure CLI on Linux, you also can use it on Windows and it works pretty well =D

it depends on what you want to do, in my personal opinion. I prefer to work with Azure CLI commands instead of Azure CMDLETS. But I'm still using PowerShell as my programing language for scripts.

Some modules on CLI are more "straight" than AZ or AzRM cmdlets.

Makeup answered 6/5, 2021 at 13:10 Comment(0)
C
0

Both are preferable because we can use either of them for writing scripts. In the case of Powershell or Azure CLI, you need to download the software in order to write scripts but Powershell is more preferred as it is an in-built tool by Microsoft. But I have also notice that giving commands through Powershell is more complex if we compare it to command prompt.

Cooperman answered 23/6, 2021 at 8:17 Comment(0)
M
0

there is an article from MS on the topic, with following outtakes:

Feature parity for Azure services doesn't always exist between Azure CLI and Azure PowerShell.

When picking the right tool, consider your past experience and current work environment.

If you work primarily with Windows systems, Azure PowerShell is a natural fit. Commands follow a verb-noun naming scheme and data is returned as objects. If you work primarily with Linux systems, Azure CLI feels more natural.

Choose the tool that uses your experience and shortens your learning curve.

Marcionism answered 4/7, 2021 at 15:40 Comment(0)
B
0

I've used both Az Powershel and cli, but when docs are ambiguous or commands are not supported, I highly recommend skipping both and going upstream to Azure Rest API.

Azure Rest API is generally called by the other commandline tools so it ends up being the most feature complete and generally well documented. It's cross platform too.

The hardest part is getting auth figured out. From powershell I usually use a format something like this, but convert to curl+cli or place in a webapp if needed. Here is a random example:

$azContext = Get-AzContext
$subscriptionId = $azContext.Subscription.Id
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$authHeader = @{
    'Content-Type'='application/json'
    'Authorization'='Bearer ' + $token.AccessToken
}     
  
$uri = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$rg/providers/Microsoft.Web/sites/$site/config/web?api-version=2022-03-01"
$Body = @{      
    "properties" = @{netFrameworkVersion = "v6.0"}
}
$Params = @{
    Uri = $uri
    Headers = $authHeader
    Method = "PUT"
    Body = $Body | ConvertTo-Json -Depth 10
}
$response = Invoke-RestMethod @Params
$response.properties.netFrameworkVersion
Beaton answered 10/8, 2022 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.