0

I'm scratching my head from last couple of days with this strange issue. I'm using GitHub workflow to run few powershell commands.

So when I tried to run Get-AzureADUser -ObjectId $User-email I'm keep getting

The term 'Get-AzureADUser' is not recognized as a name of a cmdlet,
     | function, script file, or executable program. Check the spelling of the
     | name, or if a path was included, verify that the path is correct and try
     | again.

I used below commands to install the module and check if the module is installed or not. It shows up all green. Install the Module:

Install-Module AzureAD -Scope CurrentUser -Repository PSGallery -Force

Check If Module installed:

Find-Module -Name AzureAD

or

Get-Module -ListAvailable | Where-Object {$_.Name -like '*AzureAD*'}

It's shows it is installed.

However if I'm trying to use

Find-Command -Repository PSGallery -Name Get-AzureADUser this shows

Environments : {[AzureChinaCloud, AzureChinaCloud], [AzureUSGovernment, AzureUS
               Government], [AzureCloud, AzureCloud]}
Context      : Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext

my workflow looks like this:

- name: Run Azure PowerShell script - Add users to AD Group
    uses: azure/powershell@v1
    with:
      azPSVersion: "latest"
      inlineScript: |
           Install-Module AzureAD -Scope CurrentUser -Repository PSGallery -Force
           $securePassword = "xxxx"
           $psCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "clientid" , $securePassword
        Connect-AzAccount -Credential $psCred -TenantId "tenat_id" -ServicePrincipal
        $info = Get-AzureADUser -ObjectId $User-email
        Add-AzureADGroupMember -ObjectId "aad_object_id"  -RefObjectId $info.ObjectId
        ....

Can anyone help me how can I achieve this?

change198
  • 1,647
  • 3
  • 21
  • 60
  • This looks relevant: https://stackoverflow.com/questions/56543597/the-term-connect-azuread-is-not-recognized-as-the-name-of-a-cmdlet – Azeem Jun 21 '23 at 16:29

1 Answers1

1

Check with the commandlets below: After Installing Azure ad

Install-Module AzureAD -Scope CurrentUser -Repository PSGallery -Force

Make sure to add to import the module to your library of whatever you are using in your pipeline script.

Import-module azuread Or Import-module azureadpreview Make sure to Connect to azure ad using

$Credential = Get-Credential
Connect-AzureAD -Credential $Credential  

enter image description here

To get the AzureAD modules to be used.

And then try to give Azure ad commands and you may look into @Azeem's reference.

Get-AzureADUser

enter image description here

kavyaS
  • 8,026
  • 1
  • 7
  • 19