2016-10-02 43 views
0

我試圖通過使用Invoke-WebRequest cmdlet轉換wget調用調用,但我嘗試的代碼導致出現問題。將Wget調用轉換爲PowerShell

wget --no-check-certificate -S -q --header "Accept: application/json" --header='ContentType: application/json' --header="Authorization: Bearer <TOKEN>" -O https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers 

這是我嘗試使用Invoke-WebRequest,但導致錯誤。

add-type @" 
    using System.Net; 
    using System.Security.Cryptography.X509Certificates; 
    public class TrustAllCertsPolicy : ICertificatePolicy { 
     public bool CheckValidationResult(
      ServicePoint srvPoint, X509Certificate certificate, 
      WebRequest request, int certificateProblem) { 
      return true; 
     } 
    } 
"@ 
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 

[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3") 


$username = "ebc\cloudadmin" 
$password = "are1!" | ConvertTo-SecureString -asPlainText -Force 
$cred = New-Object System.Management.Automation.PSCredential($username,$password) 


Invoke-WebRequest https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers -Credential $cred 

enter image description here

誰能幫助?

回答

1

在wget的要求,你在Authorization頭承載令牌身份驗證 - 做同樣使用PowerShell:

$headers = @{ 
    Accept = 'application/json' 
    ContentType = 'application/json' 
    Authorization = 'Bearer <TOKEN>' 
} 
Invoke-WebRequest https://10.107.174.117/itfm-cloud/rest/reports-api/export-csv?name=servers -Headers $headers