【发布时间】:2018-10-25 11:19:39
【问题描述】:
我需要从集群中获取统计信息,例如内存或 CPU 使用情况。 我正在尝试使用 Connect-VIServer 命令进行连接,但无法通过它。 我可以毫无问题地使用 vSphere 客户端访问 vCenter。
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer -server 'ServerIP' -user 'Username' -password 'Password'
$clusterName = 'ServerIP'
$stat = 'cpu.usagemhz.average','mem.usage.average'
$entity = Get-Cluster -Name $clusterName
$start = (Get-Date).AddDays(-2)
Get-Stat -Entity $clusterName -Stat $stat -Start $start |
Group-Object -Property Timestamp |
Sort-Object -Property Name |
Select @{N='Cluster';E={$entity.Name}},
@{N='Time';E={$_.Group[0].Timestamp}},
@{N='CPU GHz Capacity';E={$script:capacity = [int]($entity.ExtensionData.Summary.TotalCPU/1000); $script:capacity}},
@{N='CPU GHz Used';E={$script:used = [int](($_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value)/1000); $script:used}},
@{N='CPU % Free';E={[int](100 - $script:used/$script:capacity*100)}},
@{N='Mem Capacity GB';E={$script:mcapacity = [int]($entity.ExtensionData.Summary.TotalMemory/1GB); $script:mcapacity}},
@{N='Mem Used GB';E={$script:mused = [int](($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | select -ExpandProperty Value) * $script:mcapacity/100); $script:mused}},
@{N='Mem % Free';E={[int](100 - $script:mused/$script:mcapacity*100)}} |
Export-csv -Path C:\cluster-stats.csv
脚本运行了几分钟,但最后我得到的只是一个错误,上面写着:
Connect-VIServer : 25/10/2018 12:54:46 Connect-VIServer The underlying connection was closed: An unexpected error occurred on a send.
At line:3 char:1
+ Connect-VIServer -server 'ServerIP' -user 'Username' -password 'Password'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], ViError
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_WebException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
【问题讨论】:
标签: powershell vmware