Get-LocalGroupMember generates error for Administrators group

This has been referenced as an official bug:

https://github.com/PowerShell/PowerShell/issues/2996

Here is workaround:

http://jdhitsolutions.com/blog/scripting/2342/query-local-administrators-with-cim/

UPDATE:

I had some issues with CIM and WMI.

Here is another workaround which worked everywhere for me.

https://p0w3rsh3ll.wordpress.com/2016/06/14/any-documented-adsi-changes-in-powershell-5-0/


This is caused by empty sids in the Administrators Group. Open the Administrators group and remove the empty sids left behind from domain join/leave. Before and After cleaning up the administrators group

PS C:\WINDOWS\system32> Get-LocalGroupMember -Group "Administrators" Get-LocalGroupMember : Failed to compare two elements in the array. At line:1 char:1

  • Get-LocalGroupMember -Group "Administrators"
  •   + CategoryInfo          : NotSpecified: (:) [Get-LocalGroupMember], InvalidOperationException
      + FullyQualifiedErrorId : An unspecified error occurred.,Microsoft.PowerShell.Commands.GetLocalGroupMemberCommand
    
    
    

PS C:\WINDOWS\system32> Get-LocalGroupMember -Group "Administrators"

ObjectClass Name PrincipalSource


User MyMachine\Administrator Local
User NA\otheradmin AzureAD

you are welcome, working on a way cleaning up all empty sids from groups now.