Forum Discussion
Power BI Dashboard incrementing after running the script. How to Fix
Hi All,
Whenever i run the below scrip the data in BI dashboard keeps incrementing. Example - ESX Host - 5 then it increments to 10 Host and VM's - 61 to 122. How to fix this in power BI.
Any pointers will be much appreciated.
eport = foreach ($vCenter in $vCenters) {
Connect-VIServer $vCenter -Protocol https
}
$date = Get-Date
foreach($cluster in Get-Cluster){
$esx = $cluster | Get-VMHost
$cluster | Select @{N="DCname";E={(Get-Datacenter -Cluster $cluster).Name}},
@{N="Clustername";E={$cluster.Name}},
@{N="Total Physical Memory (GB)";E={($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum}},
@{N="Configured Memory GB";E={($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum}},
@{N="Available Memory (GB)";E={($esx | Measure-Object -InputObject {$_.MemoryTotalGB - $_.MemoryUsageGB} -Sum).Sum}},
@{N="Num of CPUs)";E={($esx | Measure-Object -Property NumCpu -Sum).Sum}},
@{N="Total CPU (Mhz)";E={($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum}},
@{N="Configured CPU (Mhz)";E={($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum}},
@{N="Number of VMs";E={($esx | Get-VM).count}},
@{N="Number of ESXi Hosts";E={$esx.count}}
$endpoint = "https://api.powerbi.com/beta/a1f1e214-7ded-45b6-81a1-9e8ae3459641/datasets/808338b1-a3bf-4572-8496-befbf5d139d1/rows?openReportSource=ReportInvitation&ctid=a1f1e214-7ded-45b6-81a1-9e8ae3459641&key=J7eHXzphYqrGINmcwFk676uGNz0Tjewrl39pKE1Zfkdaw6%2FNBYy47%2FRwO2LJU70wBZOiCmU6cZnWHyt8UcMdVg%3D%3D"
$payload = @{
"Date" = $Date
"Available Memory (GB)" =($esx | Measure-Object -InputObject {$_.MemoryTotalGB - $_.MemoryUsageGB} -Sum).Sum
"Configured Memory GB" =($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum
"Total Physical Memory (GB)" =($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum
"Clustername" =$cluster.Name
"Num of CPUs" =($esx | Measure-Object -Property NumCpu -Sum).Sum
"Total CPU (Mhz)" =($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
"Configured CPU (Mhz)" =($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
"Datacenter" =(Get-Datacenter -Cluster $cluster).Name
"Number of VMs" =($esx | Get-VM).count
"Number of ESXi Hosts" =$esx.count
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
}
Thanks
N
1 Reply
- PhilipTreacy
Super User
Hi Anonymous
Is that a PowerShell script? Sorry I'm not familiar with it. But if your script is doubling the values in your data, is it reading the current values and then adding them back to itself?
Phil