rubrikinc / rubrik-scripts-for-powershell

Collection of PowerShell Scripts created to interact to Rubrik CDM
MIT License
50 stars 58 forks source link

Invoke-WebRequest : Cannot bind parameter 'Uri'. Cannot convert value "https:///api/internal/report/CustomReport:::1af913f6-6ad9-421b-bbf7-069a20e36a91/table" to type "System.Uri". Error: "Invalid URI: The hostname could not be parsed." #153

Open KavyaKanya opened 4 years ago

KavyaKanya commented 4 years ago

Import-Module Rubrik

$server = 'xxxx' $rubrik_user = 'admin' $rubrik_pass = 'xxxx' $baseURL = "https://" + $server + "/web/bin/index.html"

function Get-RubrikReportData41 () { [CmdletBinding()] Param ( [string]$server, [string]$rubrik_user, [string]$rubrik_pass, [string]$baseURL, [string]$report_id, [System.Object]$report_query )

$headers = @{
    Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $rubrik_user,$rubrik_pass)))
    Accept = 'application/json'
}

# This block prevents errors from self-signed certificates
Add-Type -TypeDefinition @"

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 -TypeName TrustAllCertsPolicy

$report_output = @()
$has_more = $true
while ($has_more -eq $true) {
    if ($cursor -ne $null) {
        $report_query['cursor'] = $cursor
    }
    $report_response = Invoke-WebRequest -Uri $("https://"+$baseURL+"/api/internal/report/"+$report_id+"/table") -Headers $headers -Method POST -Body $(ConvertTo-Json $report_query)
    $report_data = $report_response.Content | ConvertFrom-Json
    $has_more = $report_data.hasMore
    $cursor = $report_data.cursor
    foreach ($report_entry in $report_data.dataGrid) {
        $row = '' | select $report_data.columns
        for ($i = 0; $i -lt $report_entry.count; $i++) {
            $row.$($report_data.columns[$i]) = $($report_entry[$i])
        }
        $report_output += $row
    }
}
return $report_output

}

$report_query = @{

limit = 100
sortBy = "Hour"
sortOrder = "asc"
cursor = "sring"
objectName = "string"
requestFilters = @{
organization = "string"
slaDomain = "string"
taskType = "Backup"
taskStatus = "Succeeded"
objectType = "HypervVirtualMachine"
complianceStatus = "InCompliance"
clusterLocation = "Local"
}

}

$report_id = 'CustomReport:::1af913f6-6ad9-421b-bbf7-069a20e36a91'

$a = Get-RubrikReportData41 -server $baseURL -rubrik_user $rubrik_user -rubrik_pass $rubrik_pass -report_query $report_query -report_id $report_id Write-Output ($a)

========================= I get the below error

image