Share via

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

HKPR 41 Reputation points
Jul 23, 2022, 10:40 AM

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.
5,157 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VinodKumar-0434 321 Reputation points
    Jul 23, 2022, 3:32 PM

    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"  
        }  
    }  
    
    7 people found this answer helpful.

Your answer

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