title: How to send Invoke-WebRequest with JSON body containing data from File
body: <p><strong>QUESTION:</strong><br>
  How do I put a file's contents within the JSON body of an Invoke-WebRequest without the unneeded file metadata?</p>
  
  <p>My goal is to send an HTTP request like so:</p>
  
  <pre><code>Invoke-WebRequest -Uri http://localhost:4321/updatefile `
      -ContentType 'application/json' `
      -Method POST `
      -Body $Body
  </code></pre>
  
  <p>where:</p>
  
  <pre><code>PS C:\Users\User1234&gt; $Body = ConvertTo-Json @(
      @{filename='file1.txt';filecontent=$file1},
      @{filename='file2.txt';filecontent=$file2}
  )
  
  PS C:\Users\User1234&gt; $file1 = Get-Content "C:\path\to\file1.txt"
  PS C:\Users\User1234&gt; $file2 = Get-Content "C:\path\to\file2.txt"
  </code></pre>
  
  <p>When I print the variables:</p>
  
  <pre><code>PS C:\Users\User1234&gt; echo $file1
  aaaaa
  PS C:\Users\User1234&gt; echo $file2
  bbbbb
  </code></pre>
  
  <p>...it prints the contents of the file as I expected.<br>
  But printing the file content within the <code>$Body</code> shows a lot more information I don't need:</p>
  
  <pre><code>PS C:\Users\User1234&gt; echo $Body
  {
      "filename":  "file1.txt",
      "filecontent":  {
                          "value":  "aaaaa",
                          "PSPath":  "C:\\path\\to\\file1.txt",
                          "PSParentPath":  "C:\\path\\to",
                          "PSChildName":  "file1.txt",
                          "PSDrive":  {
                                          "CurrentLocation":  "Users\\User1234",
                                          "Name":  "C",
                                          "Provider":  "Microsoft.PowerShell.Core\\FileSystem",
                                          "Root":  "C:\\",
                                          "Description":  "OS",
                                          "MaximumSize":  null,
                                          "Credential":  "System.Management.Automation.PSCredential",
                                          "DisplayRoot":  null
                                      },
                          "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\\User1234",
                                             "Drives":  "C D Y"
                                         },
                          "ReadCount":  1
                      }
  }
  </code></pre>
  
  <p>I tried setting <code>$file1</code> and <code>$file2</code> values using:</p>
  
  <pre><code>$file1 = [IO.File]::ReadAllText("C:\path\to\file1.txt")    
  $file2 = [IO.File]::ReadAllText("C:\path\to\file2.txt")
  </code></pre>
  
  <p>...but the result is the same.</p>