Skip to content
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

Expose default PowerShell User-Agent in Microsoft.PowerShell.Commands.PSUserAgent #23839

Open
Christophoclese opened this issue May 23, 2024 · 0 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@Christophoclese
Copy link

Summary of the new feature / enhancement

As a developer of a client library that makes use of Invoke-WebRequest, I would like to be able to easily extend the default User-Agent header that is sent. The Microsoft.PowerShell.Commands.PSUserAgent class provides public static strings for various common user agents, but doesn't expose its own.

After some searching I was able to find a mention of a way to access the private class member, but I'm not sure I would have been able to work this out on my own:

PS /home/cbarton> [Microsoft.PowerShell.Commands.PSUserAgent].GetMembers('Static, NonPublic').Where{$_.Name -eq 'UserAgent'}.GetValue($null,$null)
Mozilla/5.0 (Linux; Ubuntu 20.04.6 LTS; ) PowerShell/7.4.1

This would be potentially more understandable and discoverable if it were exposed in the same way as the other user agents, e.g:

PS /home/cbarton> [Microsoft.PowerShell.Commands.PSUserAgent]::PowerShell
Mozilla/5.0 (Linux; Ubuntu 20.04.6 LTS; ) PowerShell/7.4.1

The end goal was to be able to do something like this:

$CustomUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::PowerShell + " foo/x.x.x"
Invoke-WebRequest -Uri 'https://httpbin.org/headers' -UserAgent $CustomUserAgent

Proposed technical implementation details (optional)

I believe the relevant file is here. I'm not a c# developer but guessing this would go something like this:

        /// <summary>
        /// Useragent string for PowerShell (Current Version).
        /// </summary>
        public static string PowerShell => UserAgent;
@Christophoclese Christophoclese added Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. labels May 23, 2024
@iSazonov iSazonov added the WG-Engine core PowerShell engine, interpreter, and runtime label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

2 participants