powershellhelp-system

What does the -raw switch parameter in Get-Content really do in Powershell? Finding helpful documentation


I've been trying to work with an API that only accepts raw text or base64 encoded values in a JSON object. The content I'm POSTing is data from an XML file. So I used Powershell's Get-Content cmdlet (without -Raw) to retrieve the data from the .xml and then base64 encode it and sent it to the API. The API then decodes it, but the XML formatting was lost.

I found a SO post about using the -Raw switch on Get-Content, but it seems like the documentation for this switch is vague. When I used the -Raw switch, encoded it and sent it back to the API, the formatting was good.


Solution

  • As per Kory Gill's comment and your own, the built-in Get-Help and MSDN documentation should be your first port of call. But you've already RTFM!

    When that fails, ss64 is great reference for Powershell documentation and additional examples.

    Get-Content page here. It has this to say about -Raw:

    Return multiple lines as a single string (PowerShell 3.0)
    In PowerShell 2.0 use the static method: [System.IO.File]::ReadAllText(string path)