OpsaC - Operating as PowerShell code
published: January 4, 2024 author: Tinu tags: PowerShell categories: VMware
To list some properties of your VMware Aria Operations for Logs you need:
Get the sessionId for your account:
function Get-Ops4LogsToken {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[String]$Server,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[PSCredential]$Credentials
)
try{
$headers = @{
"Content-Type" = "application/json"
}
$body = [PSCustomObject] @{
username = $Credentials.UserName
password = $Credentials.GetNetworkCredential().Password
provider = "ActiveDirectory"
}
$Properties = @{
Uri = "https://$($Server):9543/api/v2/sessions"
Method = 'POST'
Headers = $headers
Body = $body | ConvertTo-Json
UseBasicParsing = $true
ErrorAction = 'Stop'
}
$response = Invoke-RestMethod @Properties
return "Bearer $($response.sessionId)"
}catch{
Write-Warning $('ScriptName:', $($_.InvocationInfo.ScriptName), 'LineNumber:', $($_.InvocationInfo.ScriptLineNumber), 'Message:', $($_.Exception.Message) -Join ' ')
$Error.Clear()
}
}
Set the SslProtocol:
$SslProtocol = 'Tls12'
$CurrentProtocols = ([System.Net.ServicePointManager]::SecurityProtocol).toString() -split ', '
if (!($SslProtocol -in $CurrentProtocols)){
[System.Net.ServicePointManager]::SecurityProtocol += [System.Net.SecurityProtocolType]::$($SslProtocol)
}
Get the token (sessionId):
$ops4logsServer = '<ops4logs.company.com>'
$ApiCredentials = Get-Credential -Message 'Ops4Logs Credentials' -UserName "$($env:USERDOMAIN)\$($env:USERNAME)"
$AuthToken = Get-Ops4LogsToken -Credentials $ApiCredentials -Server $ops4logsServer
Retrieve Log Insight version information, in the form Major.Minor.Patch-Build of all Ops4Logs Instances:
$ApiSessionHeaders = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
'Authorization' = $AuthToken
}
$LogInstances = @(
'Primary Node'
'Secondary Node'
'Third Node'
'Virtual Node'
)
$ret = foreach($s in $LogInstances){
$Properties = @{
Uri = "https://$($s):9543/api/v2/version"
Method = 'Get'
Headers = $ApiSessionHeaders
UseBasicParsing = $true
ContentType = 'application/json'
ErrorAction = 'Stop'
}
$version = Invoke-RestMethod @Properties
$version | Add-Member NoteProperty server $s
$version
}
$ret | Format-Table server,releaseName,version
API Reference on VMware Developper Documentation,