SHARE
TWEET

Invoke-WebRequest PowerShell file upload

a guest Oct 20th, 2015 986 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]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top