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

1 answer

Sort by: Most helpful
  1. VinodKumar-0434 321 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"  
        }  
    }  
    
    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.