none
What is default browner being used from PowerShell scripts? RRS feed

  • Question

  • I would like to know on what is default browner being used from PowerShell scripts, for example, based on following statement, server has a record for this connect, and I would like to know on what information of accessing the web resources are displayed on server side, such as

    1) PowerShell

    2) IE.

    3) other

    (Invoke-WebRequest -Uri $url -SessionVariable Y -UseBasicParsing).Content | Out-File -FilePath C:\Sample.txt

    Furthermore, do server recognize on whether this connection is generated by PowerShell program or not?

    Does anyone have any suggestions?
    Thanks in advance for any suggestions



    Thanks in advance for any suggestions


    Sunday, January 21, 2018 7:14 PM

Answers

All replies

  • There is no browser it is the Net webclient.  It is base code and not a browser.

    https://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    You can set the headers as needed.


    \_(ツ)_/

    Sunday, January 21, 2018 8:16 PM
  • You can do this to see what is happening:

    Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm
    .\testhtml.htm


    \_(ツ)_/

    Sunday, January 21, 2018 8:22 PM
  • I have tried www.whatismybrowser.com, even through I use different browsers to access this site, which still do not show the browsers information.  Is there any tools to check what browsers information is collected on server side based on following different approaches?

    • PowerShell
    • IE
    • Other Browsers

    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, January 22, 2018 1:27 AM
  • It is impossible for me to determine what you are asking.  The code I gave you shows that the webrequest is not using any browser.  It will always return the same thing no matter what browsers you have installed.  "Invoke-WebRequest" does not use a browser.


    \_(ツ)_/

    Monday, January 22, 2018 1:37 AM
  • PowerShell does not use any browser to make it's connection. But I think you are asking about what PowerShell sends to the server that could be used to detect that PowerShell is making the request. The UserAgent string sent by PowerShell does indicate the PowerShell version, and also hints that it is "Mozilla/5.0", which of course it is not.

     

    $request = Invoke-WebRequest "http://useragentstring.com/"
    $request.AllElements | where { $_.id -eq "uas_textfeld" } | select innertext
    

    I got similar results from PowerShell 3 and PowerShell 5.1.

        innerText
        ---------
        Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US) WindowsPowerShell/3.0

       innerText
       ---------
       Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.14393.1944

     

    You can use the -UserAgent parameter of Invoke-WebRequest to set any string you would like to use.

    Invoke-WebRequest "http://useragentstring.com/" -UserAgent "Mozilla/99.0 ( Commodore Pet 1.0 )"

     


    Mike Smith TechTrainingNotes.blogspot.com
    Books: SharePoint 2007 2010 Customization for the Site Owner, SharePoint 2010 Security for the Site Owner

    Monday, January 22, 2018 2:23 AM
  • Which is exactly what we  would expect if the client opening a session to a web server does not provide a header declaring the browser type.  The industry will default (or should default) to Mozz 5 which is the last basic Mozilla browser and is the standard all browsers are built on.

    Since the connection has no browser association the detection is the default. You can supple a header that declare any browser you like and that will be what is reflected


    \_(ツ)_/

    Monday, January 22, 2018 2:27 AM
  •  

    You can use the -UserAgent parameter of Invoke-WebRequest to set any string you would like to use.

    Invoke-WebRequest "http://useragentstring.com/" -UserAgent "Mozilla/99.0 ( Commodore Pet 1.0 )"


    I am using PowerShell to Invoke-WebRequest, but would like to set string using Chrome / Firefox / IE, so Server recognizes this web request from browsers instead of PowerShell.

    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, January 22, 2018 2:28 AM
  • Visit UserAgentString.com with the browser to emulate and copy that string. Use it with the -UserAgent parameter

    Or get "sample" useragent strings from .NET:

       $userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome

    See here:

    http://www.powershellmagazine.com/2012/11/20/pstip-powershell-and-the-pre-configured-user-agent-strings/


    Mike Smith TechTrainingNotes.blogspot.com
    Books: SharePoint 2007 2010 Customization for the Site Owner, SharePoint 2010 Security for the Site Owner

    • Marked as answer by oemMicrosoft Monday, January 22, 2018 3:35 AM
    Monday, January 22, 2018 2:34 AM
  • You can even do this:

    Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm -UserAgent 'My funcky browser'

    If you ae trying to emulate an old, unsupported, browser then just grab that browser's string and send it.


    \_(ツ)_/

    • Marked as answer by oemMicrosoft Monday, January 22, 2018 3:34 AM
    Monday, January 22, 2018 2:44 AM
  • Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm -UserAgent 'My funcky browser'

    Based on this approach, even through the content of useragent are changed to FireFox, but this web request is only generated from PowerShell with nothing to do with FireFox, would it be correct description on following statement?

    Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm -UserAgent 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20000101 Firefox/51.0'
    .\testhtml.htm

    Do you have any suggestions?
    Thanks, to everyone very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Monday, January 22, 2018 3:04 AM
  • The browser agent string is completely up to you.

    \_(ツ)_/

    Monday, January 22, 2018 3:06 AM
  • Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm -UserAgent 'My funcky browser'

    Based on this approach, even through the content of useragent are changed to FireFox, but this web request is only generated from PowerShell with nothing to do with FireFox, would it be correct description on following statement?

    Invoke-WebRequest https://www.whatismybrowser.com  -OutFile testhtml.htm -UserAgent 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20000101 Firefox/51.0'
    .\testhtml.htm

    Do you have any suggestions?
    Thanks, to everyone very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Do you understand what a browser sergeant string is?  Do you understand what it is used for and where?  Answer those questions and you will understand why your question in too vague and unanswerable.

    To use any technology you must first learn the technology to, at least, some basic degree.

    The agent string is used by the web server.  It is NOT used by the browser.  A web request can be sent with any agent string.  The server either reacts to the agent string or ignores it.


    \_(ツ)_/

    Monday, January 22, 2018 3:20 AM