Skip to content

Fixed Test-UserAdminMembership so the result is correct regardless if… #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2022

Conversation

dwknight70
Copy link
Contributor

Fix to the Test-UserAdminMembership function. The current version is only checking if the current user is a direct member of local administrators. If the user member of any groups that are in local administrators but is not a direct member, it erroneously returns false. See the discussion @ https://smsagent.blog/2016/06/30/testing-for-local-administrator-privilege-with-powershell/.

… the user is a direct member of local administrators or is a member of any groups that are in local administrators
@skycommand
Copy link
Owner

Hello. 😊 Please address the problems I've raised.

@dwknight70
Copy link
Contributor Author

I don't see where you have raised any problems - please clarify - thanks.

@skycommand
Copy link
Owner

Strange. Re-submitting my code review...

- Restore deleted prose from documentation/help
- Avoid directly dereferencing `[System.Security.Principal.WindowsIdentity]::GetCurrent()`
@skycommand skycommand merged commit f9b81b3 into skycommand:master Oct 26, 2022
@dwknight70
Copy link
Contributor Author

The code you committed is fine, but that comment truly does not apply. The elevation context is irrelevant for that function, and it will not request elevation.

@skycommand
Copy link
Owner

skycommand commented Oct 26, 2022

@dwknight70 Thanks a lot for your contribution. 🙏 I shall remember you fondly as the first person who improved my code. 🎉

I will work on improving the language and tone of the comment to which you are objecting but I believe the user must know that Test-UserAdminMembership is not the function they must use to determine whether they can run such commands as Get-ProvisionedAppxPackage -Online.

@dwknight70
Copy link
Contributor Author

Glad to be of help. Yeah, I can see how people might be confused. Code leveraging these would really want to use a combination of both functions - Test-ProcessAdminRight to see if it's in an elevated admin-context already, and Test-UserAdminMembership to check if it's even possible for them to get an elevated context. If it is, then something like this (https://gist.github.com/fearthecowboy/0781e8914ad9b3a1b104) can be used to re-launch a script in an elevated context, which will automatically trigger the UAC prompt.

@dwknight70 dwknight70 deleted the Fix-Test-UserAdminMembership branch October 26, 2022 23:54
@dwknight70
Copy link
Contributor Author

Oh, and I should mention, not only do I happen to be your first contributor, I've also never contributed to any other repos before. It's a first all the way around ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants