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?