Here is a quick script I wrote to pull the relationship’s for an object by name from the suite-api… which is exported to a CSV file.
To run the script, provide the vRops address, the pre-stored credentials and the name of the resource you wish to search…
.\GetRelationships.ps1 -vRopsAddress '192.168.88.125' -creds 'HOME' -Resource 'WINSRV2'
To create the credentials file run the following command.
$cred = Get-Credential $cred | Export-Clixml -Path "d:\vRops\config\HOME.xml"
And here is the script
param ( [String]$vRopsAddress, [String]$creds, [String]$Resource ) $ScriptPath = (Get-Item -Path ".\" -Verbose).FullName if($creds -gt ""){ $cred = Import-Clixml -Path "$ScriptPath\config\$creds.xml" $vRopsUser = $cred.GetNetworkCredential().Username $vRopsPassword = $cred.GetNetworkCredential().Password } else { echo "credentials not specified!" Exit } #vRops SSL certificate trust 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 #Lookup Function to get resourceId from Name Function GetObject([String]$vRopsObjName, [String]$vRopsServer, $User, $Password){ $wc = new-object system.net.WebClient $wc.Credentials = new-object System.Net.NetworkCredential($User, $Password) [xml]$Checker = $wc.DownloadString("https://$vRopsServer/suite-api/api/resources?name=$vRopsObjName") # Check if we get more than 1 result and apply some logic If ([Int]$Checker.resources.pageInfo.totalCount -gt '1') { $DataReceivingCount = $Checker.resources.resource.resourceStatusStates.resourceStatusState.resourceStatus -eq 'DATA_RECEIVING' If ($DataReceivingCount.count -gt 1){ $CheckerOutput = '' return $CheckerOutput } } $CheckerOutput = New-Object PsObject -Property @{Name=$vRopsObjName; resourceId=$Checker.resources.resource.identifier; resourceKindKey=$Checker.resources.resource.resourceKey.resourceKindKey} return $CheckerOutput } Function GetObjectRelationships([String]$vRopsObjID, [String]$vRopsServer, $User, $Password){ $RelationReport = @() #Call vRops API $wc = new-object system.net.WebClient $wc.Credentials = new-object System.Net.NetworkCredential($User, $Password) [xml]$Relationships = $wc.DownloadString("https://$vRopsAddress/suite-api/api/resources/$vRopsObjID/relationships") ForEach ($Relationship in $Relationships.'resource-relation'.resource.resourceKey){ $RelationReport += New-Object PSObject -Property @{ Name = $Relationship.Name Type = $Relationship.resourceKindKey } } Return $RelationReport } $ObjectLookup = GetObject $Resource $vRopsAddress $vRopsUser $vRopsPassword $RelationshipList = GetObjectRelationships $ObjectLookup.resourceId $vRopsAddress $vRopsUser $vRopsPassword $RelationshipList | Sort-object Type | export-csv "$Resource-Relationships.csv" -NoTypeInformation Remove-Variable * -ErrorAction SilentlyContinue
Example Output
Name | Type |
ESX-INF-SSD1 | Datastore |
WINSRVs | Function |
192.168.88.130 | HostSystem |
Product Licensing | Licensing |
PoweredOn:vc.vMan.ch | VM Entity Status |
PoweredOn:all | VM Entity Status |
SERVER | VMFolder |
Recent Comments