简体   繁体   中英

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

I need to list the Linux-based vCenter (VCSA) Services in powercli / powershell script. I don't know of any powercli cmdlet that will list the services. I thought of using vSphere REST API newly introduced in vSphere 6.5

The two calls I tried using postman / vSphere API explorer failed with unable to authorize:

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

Tested listing services using vSphere REST API in postman and REST explorer

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

VMware HOL screenshot

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

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.

Check: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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