Get-Content / Object Return Just need String

Im working with an API. I need to submit a certificate (key, certificate and intermediate) as strings inside a JSON. It doesnt mention encoding them in base64 or anything so i am assuming they mean raw strings, and as usual there API documentation is written for PHP not PowerShell. Example:

        name: "string",
        certificate: "string",
        key: "string",
        ca: "string"

Using Get-Content -raw i think i should be able to do this. I know that Get-Content can manipulate on delimiters like new lines, and those are important to certificates, but the main issue i have right now is that the JSON object is having additional info from Get-Content added, and i am either too tired or too stupid to see how!

$keyContent = Get-Content "C:\Users\robert\cert.key" -raw
$jsonObject = [pscustomobject]@{
                name = ""
                "key" = $keyContent
$jsonObject | convertto-json

This returns:

  "name": "",
  "key": {
    "value": ""-----BEGIN PRIVATE KEY-----\truncated by me\n-----END PRIVATE KEY-----\n",      
    "PSPath": "C:\\Users\\robert\cert.key",
    "PSParentPath": "C:\\Users\\robert",
    "PSChildName": "cert.key",
    "PSDrive": {
      "CurrentLocation": "Users\\robert",
      "Name": "C",
      "Provider": "Microsoft.PowerShell.Core\\FileSystem",
      "Root": "C:\\",
      "Description": "",
      "MaximumSize": null,
      "Credential": "System.Management.Automation.PSCredential",
      "DisplayRoot": null,
      "VolumeSeparatedByColon": true
    "PSProvider": {
      "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider",
      "HelpFile": "System.Management.Automation.dll-Help.xml",
      "Name": "FileSystem",
      "PSSnapIn": "Microsoft.PowerShell.Core",
      "ModuleName": "Microsoft.PowerShell.Core",
      "Module": null,
      "Description": "",
      "Capabilities": 52,
      "Home": "C:\\Users\\robert",
      "Drives": "C Temp Z",
      "VolumeSeparatedByColon": true,
      "ItemSeparator": "\\",
      "AltItemSeparator": "/"
    "ReadCount": 1

Which is not what i am expecting… umm help please?

What would you expect then? :wink: If you want to cut off the object information you may try the .toString() method.


:rofl: could have sworn i tried that last night… sigh. Told you i didnt know if i was stupid or tired.

Working now thank you.

Sometimes we can’t see the forest for the trees. :wink: