Recently, Microsoft released the Microsoft Graph PowerShell SDK V2 module, which includes numerous improvements such as simplified authentication, improved error handling, and enhanced speed. Excited to explore the latest version, I decided to give it a try. However, when attempting to switch to the beta version due to the limited attribute retrieval in the SDK V2, I encountered the following error:
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.
Is this a bug in the Microsoft Graph PowerShell SDK V2? Not quite. Let’s dive into the details.
Microsoft Graph SDK V2- Functionality Change
Previously, users had to utilize Select-MgProfile beta to load beta commands and Select-MgProfile v1.0 to load v1.0 commands. However, with the introduction of MS Graph PowerShell V2, beta features can no longer be accessed directly. Instead, you need to install the MS Graph PowerShell beta module separately.
This change brings a significant benefit to users targeting the beta endpoint. Beta commands will now coexist alongside v1.0 commands, eliminating the need for using Select-MgProfile beta to load beta commands. It also allows using both v1.0 and beta cmdlets within the same script without requiring a full module reload.
Install MS Graph PowerShell Module:
To install the latest MS Graph PowerShell SDK, run the following cmdlet:
1 |
Install-Module Microsoft.Graph -AllowClobber |
If you already have the MS Graph module installed and want to upgrade it to the latest version, use this cmdlet:
1 |
Update-Module Microsoft.Graph |
Please note that the above command will only upgrade the V1.0 module. As mentioned earlier, you still need to install the beta module separately to use MS Graph PowerShell beta cmdlets.
To install the Microsoft Graph beta module, use the following command:
1 |
Install-Module Microsoft.Graph.Beta -AllowClobber |
The beta module cmdlets will have the prefix ‘Beta,’ such as “Get-MgBetaUser” or “Get-MgBetaUserLicenseDetails.”
By installing both modules, you can use them side by side without needing to switch profiles. For example:
1 2 3 |
Connect-MgGraph $Users=Get-MgUser #uses v1.0 endpoint cmdlet $MFAData=Get-MgBetaUserAuthenticationMethod #uses beta cmdlet |
The Never-Ending Cycle of MS Graph Script Migrations
With the deprecation of the Msol and Azure AD PowerShell modules, Microsoft 365 admins have migrated their scripts to use MS Graph PowerShell cmdlets. However, since the SDK V1 retrieves a limited set of properties, most scripts are written to utilize the beta profile. For instance, in v1.0, “Get-MgUser” doesn’t display the ‘AssignedLicenses‘ property, so switching to the beta profile is necessary to access that detail.
Therefore, it’s essential to review your existing MS Graph scripts and migrate them to the beta module. We have already upgraded our MS Graph scripts to work with the latest updates, and you can also leverage them to manage your Microsoft 365 environment efficiently.
Here are some examples of the Microsoft 365 tasks you can accomplish using these scripts:
- Obtain Microsoft 365 users’ assigned license details
- Export an Office 365 inactive user report
- Generate an Azure AD devices report
- Get MFA status report
- Retrieve guest users and their membership report
- Generate Microsoft 365 Admin and admin roles report
- Find password last change date and expiry date report
- Retrieve Microsoft 365 users’ group membership details
- Generate Microsoft 365 users’ last logon time report
- Generate a mailbox permission report
- Set Azure AD user manager in bulk
- Manage Microsoft 365 licenses and generate reports
In conclusion, while migrating MS Graph scripts to the latest SDK version may present challenges, it is a necessary step to ensure optimal performance in managing the Microsoft 365 environment. Despite the complexities involved, the benefits of the latest SDK version, such as improved functionality and enhanced capabilities, make the migration worthwhile. Happy scripting!
Related: MS Graph: One or more errors occurred.