PowerShell script to upload a list of JSON files from a folder


Just an example.


Get-ChildItem ($PSScriptRoot + '\package') -Filter *.json |
Foreach-Object {
     $headers = @{}
     $headers['host'] = 'localhost:8080'
     $content = Get-Content $_.FullName
     $x = $content | ConvertFrom-Json
     $headers["Content-Length"] = $_.Length
     $id = $x.id
     $url = '
http://localhost:8080/' + $x.resourceType + '/' + $id
     if ($x.resourceType)
     {
         try
         {
             $response = Invoke-WebRequest -URI $url -Method Put -InFile $_.FullName -ContentType 'application/fhir+json' -Headers $headers
             Write-Host $url  ' = success type='  $x.resourceType
         }
         catch [System.Net.WebException] {
             Write-Host ($_ )

            Write-Host $url
      
         }
     }
}

blog comments powered by Disqus