PowerShell script to upload a list of JSON files from a folder0 Reacties


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
      
         }
     }
}

PowerShell script to upload a file to a remote FTP server0 Reacties

I needed a simple script to upload a file remotely to an FTP server, and found a script on StackOverflow.

However, the script could use some improvements such as SSL. Here it is. Good luck with it

$ftp = [System.Net.WebRequest]::Create("ftp://ftp.yourserverblahblah.com/public/" + $args[0])
$ftp = [System.Net.FtpWebRequest]$ftp #cast
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile #"STOR"
$ftp.Credentials = new-object System.Net.NetworkCredential("someuser","incrediblepassword****")
$ftp.UseBinary = $true
$ftp.UsePassive = $true
$ftp.EnableSsl = $true

$fullPathIncFileName = $MyInvocation.MyCommand.Definition

$currentExecutingPath = [System.IO.Path]::GetDirectoryName($fullPathIncFileName)
$file = [System.IO.Path]::Combine($currentExecutingPath, $args[0])
Write-Host "Going To Copy " + $file
# read in the file as a stream.
$content = [System.IO.File]::OpenRead($file)

# get the request stream, and copy the bytes into it
$rs = $ftp.GetRequestStream()
$content.CopyTo($rs)
$rs.Close()
$content.Close()