简体   繁体   English

如何在Powershell / Powercli中列出vCenter(VCSA)服务

[英]How to list vCenter (VCSA) services in powershell / Powercli

I need to list the Linux-based vCenter (VCSA) Services in powercli / powershell script. 我需要在powercli / powershell脚本中列出基于Linux的vCenter(VCSA)服务。 I don't know of any powercli cmdlet that will list the services. 我不知道会列出服务的任何powercli cmdlet。 I thought of using vSphere REST API newly introduced in vSphere 6.5 我想到了使用vSphere 6.5中新引入的vSphere REST API

The two calls I tried using postman / vSphere API explorer failed with unable to authorize: 我尝试使用postman / vSphere API Explorer进行的两个调用失败,无法授权:

https://{server}/rest/vcenter/services

https://{server}/rest/appliance/services

I was able to use administrator@corp.local to list vms and create new vms, so I am not sure what's going on 我能够使用administrator@corp.local列出虚拟机并创建新的虚拟机,所以我不确定发生了什么

Tested listing services using vSphere REST API in postman and REST explorer 在邮递员和REST Explorer中使用vSphere REST API测试了上市服务

 $url = "https://{server}/rest/vcenter/services"
Invoke-RestMethod -Method 'Get' -Uri $url -Credential $Cred 

VMware HOL screenshot VMware HOL屏幕截图

My questions: 1) Is there a powercli command to list services in linux based vCenter (VCSA) 2) Any idea how to have this done using vSphere REST API 我的问题:1)是否有powercli命令列出基于Linux的vCenter(VCSA)中的服务2)任何想法如何使用vSphere REST API来完成

The below worked. 下面的工作。 Please use an SSO account when prompted for credentials and confirm the account use has privilege to view the services from vSphere client. 当提示输入凭据时,请使用SSO帐户,并确认该帐户的使用具有从vSphere Client查看服务的特权。

Check: https://communities.vmware.com/thread/618154 检查: https : //communities.vmware.com/thread/618154

$vcenter = <vcsa-FQDN>
$BaseUri = "https://$vcenter/rest/"

$SessionUri = $BaseUri + "com/vmware/cis/session"

$Cred = Get-Credential

$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Cred.UserName + ':' + $Cred.GetNetworkCredential().Password))

$header = @{

    'Authorization' = "Basic $auth"

}

$authResponse = (Invoke-RestMethod -Method Post -Headers $header -Uri $SessionUri).Value

$sessionHeader = @{"vmware-api-session-id" = $authResponse }

$result = Invoke-Restmethod -Method Get -Headers $sessionHeader -Uri ($BaseUri + "vcenter/services")

$result.value.value | select Name_Key, Health, State, Description_Key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM