Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Host utilization report through Power BI

Hi , All

 

I'm trying to retrieve the Host utilization report with PowerCLI script to find out average CPU and Memory hosts utilization during period of time and push the data to BI tool, but it fails with an error for all the hosts. Looking for help.

 

Invoke-RestMethod : Invalid URI: The hostname could not be parsed.
At D:\xyz\Host-ut-BI.ps1:60 char:5
+ Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

 

 

 

 

Thanks

N

 

Import-Module VMware.VimAutomation.Core

Connect-VIServer -Server Domain.com -user "Domain\user"

 

 

$now = Get-Date

$start = $now.AddDays(-1)

 

 

$finish = $now

 

 

$SStat = @{

 

 

   Entity = Get-VMHost

 

 

   Stat = 'cpu.usage.average', 'mem.usage.average'

 

 

   Start = $start

 

 

   Finish = $finish

 

 

   Instance = '*'

 

 

   ErrorAction = 'SilentlyContinue'

 

 

}

 

 

Get-Stat @sStat |

 

 

Group-Object -Property { $_.Entity.Name } |

 

 

ForEach-Object -Process {

 

 

   New-Object -TypeName PSObject -Property ([ordered]@{

 

 

   Host = $_.Name

 

 

   Start = $start

 

 

   Finish = $finish

 

 

   CpuAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'cpu.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

 

 

   MemAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'mem.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

 

 

   })

 

 

 

$payload = @{

 

 

        "Date" = $Date

 

 

        "Host" = $Host.Name

 

 

        "CpuAvgPerc" = $CpuAvgPerc

 

 

        "MemAvgPerc" = $MemAvgPerc

 

 

    }

 

 

    Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

 

 

}

 

Disconnect-VIServer * -Confirm:$false

 

$endpoint = ""

$payload = @{

"Date" = $Date

"Host" = $Host.Name

"CpuAvgPerc" = $CpuAvgPerc

"MemAvgPerc" = $MemAvgPerc

}

Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

 

2 Replies