Advertisement
Guest User

Invoke-WebRequest PowerShell file upload

a guest
Oct 20th, 2015
3,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $user = "admin"
  2. $pass = "admin123"
  3. $pair = "${user}:${pass}"
  4.  
  5. $fileName = "0.iso";
  6. $sourceFilePath = "C:\\$fileName";
  7.  
  8. $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
  9. $base64 = [System.Convert]::ToBase64String($bytes)
  10. $basicAuthValue = "Basic $base64"
  11.  
  12. #$headers = @{ Authorization = $basicAuthValue; "Content-Length" = $sourceFilePath.Length } #Err You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
  13. $headers = @{ Authorization = $basicAuthValue }
  14. $uri = "http://nexus.lab.local:8081/nexus/content/sites/myproj/0.iso"
  15.  
  16. $output = Invoke-WebRequest -Uri $uri -Headers $headers -Method Post -InFile $sourceFilePath -ContentType "multipart/form-data" -TimeoutSec 36000 -Verbose -Debug
  17. $Error[0].InvocationInfo.Line
  18. $output
  19. Write-Host "###################################"
  20. $Error[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement