Skip to content

Conversation

adityapatwardhan
Copy link
Member

PR Summary

This pull request introduces a new helper method to retrieve the user agent string and simplifies how the PowerShell version is determined for user agent construction. The changes improve maintainability and reliability by reducing the use of PowerShell scripts and exposing a direct way to access the user agent string.

User agent string handling:

  • Added a new static method GetUserString to InternalHooks that returns the user agent string via UserAgentInfo.UserAgentString().

PowerShell version detection:

  • Updated the static constructor of UserAgentInfo to retrieve the PowerShell version using Runspace.DefaultRunspace.Version instead of executing a PowerShell script, simplifying and making the version detection more robust.

PR Context

Fixes #1676

PR Checklist

@adityapatwardhan
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adityapatwardhan
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adityapatwardhan adityapatwardhan enabled auto-merge (squash) September 5, 2025 19:08
_psVersion = ps.AddScript("$PSVersionTable").Invoke<Hashtable>()[0]["PSVersion"].ToString();
}

_psVersion = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Version.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

do we potentially need the null coalescing operator for any of these properties?

Copy link
Member

@anamnavi anamnavi left a comment

Choose a reason for hiding this comment

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

LGTM, left a comment

@adityapatwardhan adityapatwardhan merged commit 1884d13 into master Sep 5, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WDAC blocking PSResourceGet because of Dot sourcing in Find-PSResource
2 participants