Oct 03 2023 03:57 AM
Oct 03 2023 03:57 AM
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=22.214.171.124, 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!
Oct 06 2023 06:08 AM
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?
Oct 08 2023 11:56 PM
Oct 09 2023 07:07 AM
@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