我需要創建一個腳本使在3個不同的環境URL的請求,然後生成與每個環境的平均響應時間的CSV文件,我發送的每個頁面無法轉換參數「地址」,值爲:「System.Object []」,爲「DownloadString」鍵入「System.Uri」:「無法轉換」System.Object []「
但是我得到這個錯誤:
Cannot convert argument "address", with value: "System.Object[]", for "DownloadString" to type "System.Uri": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Uri".
這裏是我的代碼:
function ResponseTime($CommonName,$URL, $environment)
{
$Times = 5
$i = 0
$TotalResponseTime = 0
While ($i -lt $Times) {
$Request = New-Object System.Net.WebClient
$Request.UseDefaultCredentials = $true
$Start = Get-Date
$PageRequest = $Request.DownloadString($URL)
$TimeTaken = ((Get-Date) - $Start).TotalMilliseconds
$Request.Dispose()
$i ++
$TotalResponseTime += $TimeTaken
}
$AverageResponseTime = $TotalResponseTime/$i
Write-Host Request to $CommonName took $AverageResponseTime ms in average -ForegroundColor Green
$details = @{
Date = get-date
AverageResponseTime = $AverageResponseTime
ResponseTime = $Destination
Environment = $environment
}
$results += New-Object PSObject -Property $details
}
ResponseTime 'app homepage' 'https://urlproduction', 'PRODUCTION'
ResponseTime 'app homepage' 'https://urlQA', 'QA'
ResponseTime 'app homepage' 'https://urltest', 'TEST'
$results | export-csv -Path c:\so.csv -NoTypeInformation
爲什麼你有HTTPS之間的逗號:字符串//部分和「生產'... ? *提示* – t0mm13b
另外,將網址轉換爲'[System.Uri]'。 – t0mm13b