$baseURI = "https://upload.gridprotectionalliance.org/Upload/TEST" $basePath = "" $basePath = $(Resolve-Path -LiteralPath $basePath).Path Get-ChildItem -LiteralPath $basePath -Recurse -File | ForEach-Object { $fileName = $_.Name $filePath = $_.FullName $folderPath = [System.IO.Path]::GetDirectoryName($filePath) Push-Location -LiteralPath $basePath $relativeFolderPath = Resolve-Path -LiteralPath $folderPath -Relative Pop-Location $uriPath = $relativeFolderPath.TrimStart('.', '\').Replace('\', '/') $uri = "$baseURI/$uriPath" $bytes = [System.IO.File]::ReadAllBytes($filePath) $encoding = [System.Text.Encoding]::GetEncoding("ISO-8859-1") $text = $encoding.GetString($bytes) $boundary = [System.Guid]::NewGuid().ToString() $LF = "`r`n" $bodyLines = ( "--$boundary", "Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"", "Content-Type: application/octet-stream$LF", $text, "--$boundary--$LF" ) -join $LF Write-Host "Uploading `"$fileName`" to `"$uri`"..." Invoke-WebRequest -Uri $uri -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines }