Skip to content

Add PSVersionUtility to retrieve PowerShell version and update cmdlets for admin checks #4788

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 11 commits into from
Mar 13, 2025

Conversation

gautamdsheth
Copy link
Collaborator

Before creating a pull request, make sure that you have read the contribution file located at

https://github.com/pnp/powerShell/blob/dev/CONTRIBUTING.md

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #X, partially fixes #Y, mentioned in #Z, etc.

What is in this Pull Request ?

Please describe the changes in the PR.

Guidance

  • You can delete this section when you are submitting the pull request.*
  • Please update this PR information accordingly. We use this as part of our release notes in monthly communications.
  • Please target your PR to Dev branch. If you do not target the Dev branch we will not accept this PR.

@@ -94,6 +94,11 @@ public class RegisterAzureADApp : BasePSCmdlet, IDynamicParameters

protected override void ProcessRecord()
{
if (PSUtility.IsUserLocalAdmin())
{
WriteWarning("Running this cmdlet in requires you to run PowerShell as an administrator due to a regression in .NET 9.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the word bug instead of regression? More (non dev) people will understand that better, I would think?

{
return new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be a return null as it cannot be defined in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only impacts Windows , for the rest , it works fine.

});

#pragma warning disable CA1416 // Validate platform compatibility
public static bool IsUserLocalAdmin()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a nillable bool? See comment below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only impacts Windows , for the rest , it works fine.

@gautamdsheth gautamdsheth merged commit 4248c1d into pnp:dev Mar 13, 2025
2 checks passed
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