Share via

check if i'm logged to azure or not using powershell script in Azure Functions

HKPR 41 Reputation points
2022-07-23T10:40:02.367+00:00

Could anyone help on how to write the function script in PowerShell to verify If my azure session is logged in?

Using Connect-AzAccount will not log automatically I believe.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Vinod Nallavade 331 Reputation points
    2022-07-23T15:32:47.917+00:00

    Hi @HKPR , Thanks for reaching out Microsoft Q&A.
    Here is the function snippet that will help you to check if have a valid session or not.

    function Login()  
    {  
        $context = Get-AzContext  
      
        if (!$context)   
        {  
            Connect-AzAccount  
        }   
        else   
        {  
            Write-Host " Already connected"  
        }  
    }  
    

    Was this answer helpful?

    8 people found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.