Get-LocalGroupMember -Group Administrators bug

See original GitHub issue

we stumbled on the following bug.

I think there is the problem, that a non existing SID is in this group, and it cannot be skipped.

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> $error[0] | fl * -force

writeErrorStream : True

PSMessageDetails :

Exception : System.InvalidOperationException: Failed to compare two elements in the array. —> System.NullReferenceException: Object reference not set to an

                    instance of an object.

                       at Microsoft.PowerShell.Commands.GetLocalGroupMemberCommand.<>c.<ProcessesMembership>b__20_0(LocalPrincipal p1, LocalPrincipal p2)

                       at System.Collections.Generic.ArraySortHelper`1.SwapIfGreater(T[] keys, IComparer`1 comparer, Int32 a, Int32 b)

                       at System.Collections.Generic.ArraySortHelper`1.DepthLimitedQuickSort(T[] keys, Int32 left, Int32 right, IComparer`1 comparer, Int32 depthLimit)

                       at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)

                       --- End of inner exception stack trace ---

                       at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)

                       at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)

                       at System.Collections.Generic.List`1.Sort(Comparison`1 comparison)

                       at Microsoft.PowerShell.Commands.GetLocalGroupMemberCommand.ProcessesMembership(IEnumerable`1 membership)

                       at Microsoft.PowerShell.Commands.GetLocalGroupMemberCommand.ProcessRecord()

TargetObject :

CategoryInfo : NotSpecified: (😃 [Get-LocalGroupMember], InvalidOperationException

FullyQualifiedErrorId : An unspecified error occurred.,Microsoft.PowerShell.Commands.GetLocalGroupMemberCommand

ErrorDetails :

InvocationInfo : System.Management.Automation.InvocationInfo

ScriptStackTrace : at <ScriptBlock>, <No file>: line 1

PipelineIterationInfo : {0, 1}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
flanagansshenaniganscommented, Sep 10, 2019

Script for cleaning up, so that you can continue.

$administrators = @(
([ADSI]"WinNT://./Administrators").psbase.Invoke('Members') |
% { 
 $_.GetType().InvokeMember('AdsPath','GetProperty',$null,$($_),$null) 
 }
) -match '^WinNT';

$administrators = $administrators -replace "WinNT://",""

$administrators

foreach ($administrator in $administrators)
{
    
    if ($administrator -like "$env:COMPUTERNAME/*" -or $administrator -like "AzureAd/*")
    {
        continue;
    }

    Remove-LocalGroupMember -group "administrators" -member $administrator
}
1reaction
iSazonovcommented, Jun 20, 2018

a comment of yours on the linked issue suggests that is disabled on purpose.

Currently we have WCP in the project and we can enable on Windows cmdlets and feature that were turned off due to lack of APIs in .Net Core.

Short of testing the availability of a command in a console window, is there an easy way to tell from the source code what commands are currently disabled?

You can look DefaultCommands.Tests.ps1. (In csproj files you can see Compile Remove=. In cs file you can see if UNIX or if !Unix.)

What’s the policy in this scenario on reporting issues …

Report on UserVoice and link the post in Issue in the repo. I think with the advent of WCP inactive code will become much less.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get-LocalGroupMember generates error for Administrators ...
Any idea why the PowerShell Get-LocalGroupMember command is generating an error on the Administrators group whereas net localgroup works as does ...
Read more >
Get-LocalGroupMember : Failed to compare two elements in ...
Fix Powershell error Get-LocalGroupMember Failed to compare two elements in the array. ... Get-LocalGroupMember -Group Administrators.
Read more >
get-localgroupmember Workaround : r/PowerShell
If there are deleted accounts in a group, this command fails with this error: Get-LocalGroupMember -Group "Administrators"
Read more >
Deleting admin local group member script doesnt work
The main issue is your use of Write-Error in combination with $ErrorActionPreference = 'Stop' , since the preference is Stop, ...
Read more >
Get-LocalGroupMember generates error for ... - YouTube
Get-LocalGroupMember generates error for Administrators group Helpful? Please support me on Patreon: https://www.patreon.com/roelvandepaar ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found