What settings / permissions are required to retrieve output from the Get-EsxTop cmdlet?
I don't receive an error, but I don't receive any data, either.
Thanks
What exactly did you try?
Did you see ESXTOP Available Through PowerCLI
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is the sample powershell code.
It ends up calling FetchStats like the samples I have seen.
Richard
##############################
$host.ui.RawUI.WindowTitle = "Collectvmware VC01
Get-EsxTop-Hosts 09/20/2017 15:01:24";
$moduleList = @(
"VMware.VimAutomation.Core",
"VMware.VimAutomation.Vds",
"VMware.VimAutomation.Cloud",
"VMware.VimAutomation.PCloud",
"VMware.VimAutomation.Cis.Core",
"VMware.VimAutomation.Storage",
"VMware.VimAutomation.HorizonView",
"VMware.VimAutomation.HA",
"VMware.VimAutomation.vROps",
"VMware.VumAutomation",
"VMware.DeployAutomation",
"VMware.ImageBuilder",
"VMware.VimAutomation.License"
"SQLPS"
)
$loaded = Get-Module -Name $moduleList -ErrorAction
SilentlyContinue | % {$_.Name}
$registered = Get-Module -Name $moduleList
-ListAvailable -ErrorAction SilentlyContinue | % {$_.Name}
$notLoaded = $registered | ? {$loaded -notcontains
$_}
Write-Host "about to import modules"
foreach ($module in $registered) {
if ($loaded -notcontains $module) {
Write-Progress -Activity $module
Write-Host "about to import $module"
Import-Module $module
}
}
set-PowerCLIConfiguration -InvalidCertificateAction Ignore -confirm:$false -Scope Session
Function Get-EsxtopAPI {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]$VMHost
)
$serviceManager = Get-View
($global:DefaultVIServer.ExtensionData.Content.serviceManager) -property "" -ErrorAction SilentlyContinue
$locationString = "vmware.host." +
$VMHost.Name
$services = $serviceManager.QueryServiceList($null,$locationString)
foreach ($service in $services) {
if($service.serviceName -eq "Esxtop") {
$serviceView = Get-View
$services.Service -Property "entity"
$serviceView.ExecuteSimpleCommand("CounterInfo")
break
}
}
}
Function Get-EsxtopStat {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl]$VMHost
)
$serviceManager = Get-View
($global:DefaultVIServer.ExtensionData.Content.serviceManager) -property "" -ErrorAction SilentlyContinue
$locationString = "vmware.host." +
$VMHost.Name
Write-Host "vmhost: " $VMHost.Name
Write-Host "location: "$locationString
$services = $serviceManager.QueryServiceList($null,$locationString)
foreach ($service in $services) {
$service.serviceName | fl *
if($service.serviceName -eq "Esxtop")
{
$serviceView = Get-View
$services.Service -Property "entity"
$serviceView.ExecuteSimpleCommand("FetchStats")
$serviceView.ExecuteSimpleCommand("FreeStats")
break
}
}
}
connect-viserver -server 192.xxx.xxx.xxx -username administrator@vsphere.local
-password wwwwwww
$mytime=Get-Date -UFormat %T
Write-Host time $mytime
$host.ui.RawUI.WindowTitle = "Collectvmware VC01 cppesx01.xxxx.xxx.com Get-EsxTop $mytime";
Write-Host "***Get-VMHost -Name
"cppesx01.xxxx.xxx.com" PIPE Get-EsxtopAPI output***"
Get-VMHost -Name "cppesx01.xxxx.xxx.com" | Get-EsxtopAPI
Write-Host "***Get-VMHost -Name "cppesx01.xxxx.xxx.com" PIPE Get-EsxtopStat output***"
Get-VMHost
-Name "cppesx01.xxxx.xxx.com" | Get-EsxtopStat
Disconnect-VIServer * -Confirm:$false
###############################################
That is not using Get-EsxTop.
The function Get-EsxTopStat is calling the esxtop service directly, as William described in Using the vSphere API in vCenter Server to collect ESXTOP & vscsiStats metrics
Under which account are you running this?
An account that has the admin role on the ESXi node?
And you are connected to the ESXi node I assume?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I realize the function is using a service named Esxtop while connected to a vCenter- I am attempting to avoid connecting to a ESXi host directly.
The account has Service Manager role enabled (I am informed.)
When I use this in an environment that works, I get back:
vmhost: cppesx01.xxxx.com <== from a Write-Host
location: vmware.host.cppesx01.xxxx.com <== from a Write-Host
Esxtop <== from a $service.serviceName | fl *
==NUM-OF-OBJ== <== from the $serviceView.ExecuteSimpleCommand("FetchStats")
|Server|PCPU,1|PMem,1|Sched,1|SCSI,1|Nfs,1|Vscsi,1|Net,1|Interrupt,1|Power,1|
(a lot of stat info follows as expected.)
Is there a condition that would cause:
$serviceManager = Get-View ($global:DefaultVIServer.ExtensionData.Content.serviceManager) -property "" -ErrorAction SilentlyContinue
to fail, and exit the function Get-EsxTop immediately?
Thanks