Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CLI - run a script file

What is the process for running a set of AZ commands contained in a file? What should the file extension be? For example, the following commands are contained in a file called 'sample.ps1'.

az login --subscription "demo-sub1"

az group create \

    --name "demo-rg" \

    --location "West US 2"

Is there an AZ command to run from within Powershell that will load/run this file? .\sample.ps1 does not seem to work as expected. The login prompt is displayed, but when I pick the account to log in to, nothing happens, the "Pick an Account" screen stays up, whereas normally just running the az login command from PS would work, then redirect. In this case it just hangs and the second line of the script never gets executed.

like image 929
Mike Avatar asked Feb 27 '26 07:02

Mike


1 Answers

in this case - powershell is just a shell. for example, the following works just fine inside the sample.ps1:

az login
az group list

the only caveat - powershell uses backtick as a line continuation character, not \. so your code should look like this:

az login --subscription "demo-sub1"
az group create `
    --name "demo-rg" `
    --location "West US 2"
like image 129
4c74356b41 Avatar answered Mar 02 '26 13:03

4c74356b41



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!