Forum Discussion

SonJim212's avatar
SonJim212
Copper Contributor
Oct 03, 2023

Trying to use Remove-MgGroupMemberByRef but getting errors

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
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=1.33.0.0, 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!

  • randriksen_'s avatar
    randriksen_
    Brass Contributor

    SonJim212 

    Hi!

     

    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?

     

    -Ole

Resources