Unable to install AzureAd module using Install-Module -Name AzureAD in ADO pipeline

Viewed 1979

I am trying to execute Get-AzureADServicePrincipal in a azure powershell task in ADO. I need to get service principal for me to then connect to get ServicePrincipalId and ServicePrincipalkey. As part of this I am trying the below, as an inline script

Install-Module -Name AzureAD Get-AzureADServicePrincipal

But this keeps failing as,

WARNING: User declined to install module (AzureAD)

[error]The term 'Get-AzureADServicePrincipal' is not recognized as the name of a cmdlet

Please could some one help? Thanks

2 Answers

Install-Module is prompting for user input. Specify the -Force flag.

If you are using host agent. Better to install a module only for the current user

This example downloads and installs the newest version of a module, only for the current user. Also add -Force

Install-Module -Name PowerShellGet -Scope CurrentUser -Force

Then you need to call the Connect-AzureAD cmdlet before calling any other cmdlets.

Finally Get-AzureADServicePrincipal.

Related