sorry if iam asking too many questions here .
but what has happened i dont have administrator@vsphere.local password for this vcenter so i cant use connect-cisserver to get vcsa health .
i am trying to create a similar invoke-restmethod way so that i can get vcsa health status using domain id .
and for this method to work iam stuck at preparing base url and then system health url as shown in orange .if yu can check this works in yur test lab .
###############################################
# Configure the variables below for the vCenter
################################################
$RESTAPIServer = "vcenter1"
# Prompting for credentials
$Credentials = Get-Credential -Credential $null
$RESTAPIUser = $Credentials.UserName
$Credentials.Password | ConvertFrom-SecureString
$RESTAPIPassword = $Credentials.GetNetworkCredential().password
################################################
# Nothing to configure below this line - Starting the main function of the script
################################################
# Adding certificate exception to prevent API errors
################################################
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
################################################
# Building vCenter API string & invoking REST API
################################################
$BaseAuthURL = "https://" + $RESTAPIServer + "/rest/com/vmware/cis/"
#$BaseAuthURL = "https://" + $RESTAPIServer + "/rest/cis/"
#$BaseURL = "https://" + $RESTAPIServer + "/rest/vcenter/"
$BaseURL = "https://" + $RESTAPIServer + "/rest/appliance/health"
$vCenterSessionURL = $BaseAuthURL + "session"
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+":"+$RESTAPIPassword))}
$Type = "application/json"
# Authenticating with API
Try
{
$vCenterSessionResponse = Invoke-RestMethod -Uri $vCenterSessionURL -Headers $Header -Method POST -ContentType $Type -Verbose
}
Catch
{
$_.Exception.ToString()
$error[0] | Format-List -Force
}
# Extracting the session ID from the response
$vCenterSessionHeader = @{'vmware-api-session-id' = $vCenterSessionResponse.value}
###############################################
# Getting list of VMs
###############################################
#$VMListURL = $BaseURL+"cluster"
$app_health_URL = $BaseURL+"system"
Try
{
$systemhealth_json = Invoke-RestMethod -Method Get -Uri $app_health_URL -Headers $vCenterSessionHeader -ContentType $Type -Verbose
$system_health = $systemhealth_json.value
}
Catch
{
$_.Exception.ToString()
$error[0] | Format-List -Force
}
$system_health
#$VMList | Format-Table -AutoSize
###############################################
# End of script
###############################################