Trying to use Remove-MgGroupMemberByRef but getting errors

Copper Contributor

We are trying to setup an automation of removing users from a security group at the end of each day. I want to use the Remove-MgGroupMemberByRef cmdlet but I cannot for the life of me get it working. I am getting the below error:


Remove-MgGroupMemberByRef : The 'Remove-MgGroupMemberByRef' command was found in the module 'Microsoft.Graph.Groups', but the module could not be loaded. For more information, run 'Import-Module Microsoft.Graph.Groups'.
At line:1 char:1
+ Remove-MgGroupMemberByRef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Remove-MgGroupMemberByRef:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

So I try to import the module based on the error:


import-module Microsoft.Graph.Groups
Import-Module : Could not load file or assembly 'Azure.Core, Version=, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
+ import-module Microsoft.Graph.Groups
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

What I have done to try resolve:

- Installed latest version of MS Graph Module 2.6.1 (Including Beta)

- Installed latest version of Az module 10.4.1

- Tried running both standard and beta versions of the command but same issue

- Set execution policy to unrestricted temporarily for testing


We connect using a certificate / service principal which has satisafactory permissions to remove users from groups.


Hope someone can help!

3 Replies




I just tried to install microsoft.graph.groups on a blank computer here, and from what I can see, it doesn't require the az modules, all the other module requirements are microsoft.graph.authentication.

But it has a requirement for: DotNetFrameworkVersion = '4.7.2'

So maybe have a look at the .Net version you have installed?



Hi Ole,
Just checked and we have that .Net version installed.
it's very strange.
Should I remove and reinstall maybe?

@SonJim212 I think that's what I would do. 

or try to run the .Net repair tool: Microsoft .NET Framework Repair Tool is available - Microsoft Support