You may come across the error message around Select-MgProfile not being recognized anymore in your Azure automation code or scheduled scripts that connects to Entra ID (Azure AD) using Microsoft Graph.
The full error message is given below.
Select-MgProfile : The term ‘Select-MgProfile’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Select-MgProfile -Name “beta” +
~~~~ + CategoryInfo : ObjectNotFound: (Select-MgProfile:String) , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException.
Microsoft Graph SDK v2
Before Graph SDK v2 was released, admins used the “Select-MgProfile beta” command to execute beta commands and “Select-MgProfile v1.0” for the v1.0 commands. And this worked really well.
With the introduction of Graph SDK v2, Microsoft has stopped accessing the beta endpoint within the v2 module. If you want to access beta endpoint and already have Graph SDK v2 installed, you need to install the Graph Beta module separately.
The new beta module commands have the word ‘beta’ in the commands, for example, Get-MgBetaUser. The same command within v2 will be Get-MgUser.
How To Fix “Select-MgProfile is not recognized” error?
If you are running a code that has v1.0 commands and you upgraded your Graph SDK on the Hybrid worker server or the server from which you run the scheduled scripts, it may be necessary to comment out the “Select-MgProfile beta” line (depends on the code).
If you want to access the beta endpoint commands and have upgraded your SDK to v2, you need to install the Graph Beta module as well. This way, you can use both modules (v2 & Beta) side by side without needing to switch profiles.
Install Graph PowerShell Beta Module
Run the command below in PowerShell to install the Graph Beta module.
Install-Module -Name Microsoft.Graph.Beta
If you want to install a particular version of the Beta module (for whatever reason), you need to use the ‘RequiredVersion’ parameter. For example, run the command below to install v2.8.0.
Install-Module -Name Microsoft.Graph.Beta -RequiredVersion 2.8.0
Update Graph PowerShell Beta Module
Run the command below to update the Beta SDK to the latest version. Updating the Graph SDK v2.0 does not update the beta module.
Remove Graph PowerShell Beta Module
Run the command below to remove the Beta SDK completely.
Uninstall-Module Microsoft.Graph.Beta -AllVersions
Please let me know if you have any questions in the comments section.