Azure Bat Script

Handian Sudianto 4,451 Reputation points
2023-05-31T02:34:29.56+00:00

Hello

I have script to list all web app, but we still need manually connect to the azure via power shell then execute the script. Can we make bat script to automate this process?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,356 questions
{count} votes

Accepted answer
  1. Sedat SALMAN 13,345 Reputation points
    2023-06-01T13:45:11.44+00:00

    if you do not want any prompt to connect to Azure
    you can create a script and pass a connection parameter (this is generally not accepted as a safe method
    but if you think you can save these files in a secure way you can insert connection parameters to the script as follows)

    # Define your service principal credentials
    $azureAppId="<Your Azure App ID>"
    $azurePassword="<Your Azure Password>"
    $azureTenantId="<Your Azure Tenant ID>"
    
    # Create a PS credential object
    $psCred = New-Object System.Management.Automation.PSCredential($azureAppId, (ConvertTo-SecureString $azurePassword -AsPlainText -Force))
    
    # Login to Azure
    Connect-AzAccount -Credential $psCred -Tenant $azureTenantId -ServicePrincipal
    
    # Get all web apps
    Get-AzWebApp
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Luke Murray 10,896 Reputation points MVP
    2023-05-31T03:40:48.8766667+00:00

    Not with bat directly, but you could download and connect to the Azure API via curl - https://jiasli.github.io/azure-notes/common/rest-curl.html

    Although you may be better off to use PowerShell, and Invoke-Restmethod, or the Azure powershell commandlets.

    https://java2blog.com/run-batch-file-powershell/

    0 comments No comments