question

DheerajAwale-4542 avatar image
0 Votes"
DheerajAwale-4542 asked DheerajAwale-4542 edited

azure function powershell Set-AzContext throws exception

Below is setup of my Az Powershell Func
requirements.psd1:
141327-1.png

profile.ps1 contents:
141358-2.png

powershell code:
141363-3.png

After all this, it throws ERROR: Please provide a valid tenant or a valid subscription.
Error details:
141346-4.png


windows-server-powershellazure-functions
1.png (4.2 KiB)
2.png (14.5 KiB)
3.png (32.0 KiB)
4.png (133.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
1 Vote"
MayankBargali-MSFT answered DheerajAwale-4542 edited

@DheerajAwale-4542 As per the error message looks like your Tenant or subscription ID is invalid. Can you please confirm if this is correct?
You can update your requirements.psd1 Az.Accounts pointing to the latest version and as per the code I don't see you are using legacy AzureRm commands so you can comment Enable-AzureRMAlias

 Az.Accounts' = '2.*'

I have tested the same with the below setting and couldn'tt observe any issue. Please make sure that you have enabled the Identity on your function app.

141653-image.png

141682-image.png

141674-image.png


image.png (69.5 KiB)
image.png (10.0 KiB)
image.png (17.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You are right. Function App needs 'Managed Identity' to access either subscription or the Azure resource he is trying to access to.
My organization didn't allow me to set Identities. I did it using Manager's account.
For Anyone who comes here for answer, here is the link:
connect-azaccount-error-when-running-azure-functions-coded-in-powershell


0 Votes 0 ·