SOLVED

Get-LocalGroupMember does not run remotely

Copper Contributor

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 ?

6 Replies
best response confirmed by DamienFR68 (Copper Contributor)
Solution

@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-..., 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.

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?
And Get-LocalGroupMember -Group Administrateurs | Where-Object { $_.PrincipalSource -eq "ActiveDirectory" does work on those machines interactively using powershell_ISE.exe of poweshell.exe?
I have tried the command in PowerShell ISE (as admin) on one of the servers, still the same error message.
Ok, so if you do Install-Module Microsoft.PowerShell.LocalAccounts , does it work then?

C:\Users\HarmVeenstra> get-command -Module Microsoft.PowerShell.LocalAccounts

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Disable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Enable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
The install-module does not work, probably because I do not have the necessary network rights.
After further digging, it appears that the script works on (most) W2019 and later, So I have extracted what I can and worked with it.
Thank you for your answers and the support!
1 best response

Accepted Solutions
best response confirmed by DamienFR68 (Copper Contributor)
Solution

@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-..., 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.

View solution in original post