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 runGet-AzureADUser -ObjectId $User-emailI'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.PSAzureContextmy 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?
11 Answer
Check with the commandlets below: After Installing Azure ad
Install-Module AzureAD -Scope CurrentUser -Repository PSGallery -ForceMake sure to add to import the module to your library of whatever you are using in your pipeline script.
Import-module azureadOrImport-module azureadpreviewMake sure to Connect to azure ad using
$Credential = Get-Credential
Connect-AzureAD -Credential $Credential 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