Forum Discussion

DamienFR68's avatar
DamienFR68
Copper Contributor
Dec 06, 2023

Get-LocalGroupMember does not run remotely

Hello,

I am trying to obtain a list of all the local administrators on a set of servers using the following command as part of a larger script :

 

 

$LocalAdmins=Invoke-Command -ComputerName $Targets -ScriptBlock { Get-LocalGroupMember -Group Administrateurs | Where-Object { $_.PrincipalSource -eq "ActiveDirectory" } }

 

 

However I get an error message on each server saying that «Get-LocalGroupMember» is not recognized as applet command name, function, script or executable program.

I am running PowerShell as admin, and the command works on my local machine.

Do you see what I am missing ?

  • DamienFR68 It could be that the LocalAccounts module is not on the server. You could try to install it using Install-Module LocalAccounts. See also https://stackoverflow.com/questions/43989815/cant-find-microsoft-powershell-localaccounts-module-or-run-get-localuser, it could be (don't know what Server Operating System you have that the Windows Management Framework is not installed)

    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.

    If one of the posts was helpful in other ways, please consider giving it a Like.

    • DamienFR68's avatar
      DamienFR68
      Copper Contributor
      Thank you for your answer Harm.
      I have several windows server versions running, from 2008 R2 to 2022, with the same error on all.
      I have tried using the Install-Module LocalAccounts command on one server (W2012R2) to check, but I get the exact same error message as the one I obtained when running my original script. Do you see what could explain that?
      • Harm_Veenstra's avatar
        Harm_Veenstra
        MVP
        And Get-LocalGroupMember -Group Administrateurs | Where-Object { $_.PrincipalSource -eq "ActiveDirectory" does work on those machines interactively using powershell_ISE.exe of poweshell.exe?

Resources