Hi All,
I want to run the script for multiple vcenter with saved credential C:\credential.ps1 file. Looking for help to modify the script. Right now, i have to connect each vcenter and run the script.
will the below command will work ? Any pointers will be much appreciated.
$Creds = Get-Credential -Message "Enter username and password" -ErrorAction SilentlyContinue
$vCenters = (Get-Content "C:\VC.txt")
$report = foreach ($vCenter in $vCenters) {
Connect-VIServer $vCenter -Protocol https -Credential $Creds | Out-Null
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="Nuber 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/6ab225bd-c265-4649-b971-a3a438d04b1f/rows?key=dL9orzw1YMWColkVEJRMjoosEIOC5ESr%2BkNovk4fJYMYAPNWE%2FweU1Aiu1YjGwFkozKKhuqCuDtbpZztuGJAJg%3D%3D"
$payload = @{
"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
V