
Question:
I am trying to fetch AAD app info using "Get-AzureADApplication" command. but getting the below error-
Get-AzureADApplication : You must call the Connect-AzureAD cmdlet before calling
any other cmdlets.
At C:\Users\v-pasahu\Desktop\Sample.ps1:18 char:11
+ if($app = Get-AzureADApplication -Filter "DisplayName eq '$($AppName) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureADApplication], AadNee
dAuthenticationException
+ FullyQualifiedErrorId : Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthe
nticationException,Microsoft.Open.AzureAD16.PowerShell.GetApplication
Answer1:According to the error message, you need to run the command Connect-AzureAD
first.
Besides, if you do not <a href="https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0" rel="nofollow">install azure powershell module</a>, you should install it before using azure ad powershell.
Answer2:Looking at the comments you have said you want to run this in the non interactive flow. To do this you must follow the instructions here to log in as a <a href="https://docs.microsoft.com/en-us/powershell/azure/active-directory/signing-in-service-principal?view=azureadps-2.0" rel="nofollow">service principal</a>.
Alternatively depending on what you are trying to do you may find it easier to Login using the AzureRm cmdlets.