Functions/Get-vROPsRelationship.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Function Get-vROpsRelationship{
    <#
        .Synopsis
            This funtion retreives the relationships for a vROps object.
 
        .DESCRIPTION
            This funtion retreives the relationships for a vROps object. A connection must already have been established.
 
        .PARAMETER OMServer
            FQDN or IP address of Operations Manager server to connect to.
 
        .PARAMETER ID
            This is the ID of the resource to be investigated.
 
        .PARAMETER AuthToken
            Authorisation Token that has been generated previously, either via Connect-vROpsRASession or another method.
 
        .PARAMETER AuthResource
            Authorisation Resource object that has been generated previously, either via Connect-vROpsRASession or another method.
 
        .EXAMPLE
            $AuthToken = (Connect-vROpsRASession -OMServer vROpsOMServer.CentralIndustrial.eu -Credentials $OMCreds).Token
            $Relationships = Get-vROpsRelationship -OMServer vROpsOMServer.CentralIndustrial.eu -ID $Volume.Id -AuthResource $AuthToken
 
        .EXAMPLE
            $AuthResource = Connect-vROpsRASession -OMServer 10.11.12.13 -Credentials $OMCreds -UseUntrustedSSLCertificates
            $Relationships = Get-vROpsRelationship -OMServer 10.11.12.13 -ID $Volume.Id -AuthResource $AuthResource
 
        .OUTPUTS
            This will output The relationship of a resource
 
        .Notes
            .NOTES
            Version: 1.1
            Author: Lars Panzerbjørn
            Creation Date: 2019.11.22
            Purpose/Change: Initial script development
    #>

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory,ParameterSetName="Token")]
        [Parameter(Mandatory,ParameterSetName="Object")]
        [ValidateNotNullOrEmpty()]
        [string]$OMServer,
        
        [Parameter(Mandatory,ParameterSetName="Token")]
        [Parameter(Mandatory,ParameterSetName="Object")]
        [ValidateNotNullOrEmpty()]
        [string]$ID,
        
        [Parameter(Mandatory,ParameterSetName="Token")]
        [ValidateNotNullOrEmpty()]
        [PSObject]$AuthToken,

        [Parameter(Mandatory,ParameterSetName="Object")]
        [ValidateNotNullOrEmpty()]
        [PSObject]$AuthResource
    )
    Begin{
        IF ($PSCmdlet.ParameterSetName -eq "Object") {$AuthToken = $AuthResource.Token}
        $Authorization = "vRealizeOpsToken $AuthToken"
        $JSONContentType = 'application/json'
        $Headers = @{accept=$JSONContentType; Authorization=$Authorization}
        $Uri = "https://$OMServer/suite-api/api/resources/$ID/relationships"
        #$PageSize = "5000" #Maximum is 10000
        #$Page = 0
        $RelationshipReport = @()
    }
    Process{
        $Relationships = Invoke-RestMethod -Uri $Uri -ContentType $JsonContentType -Headers $Headers
        #Parse the output to get the relationships and add it to a standard object
        ForEach ($Relationship in $Relationships.resourceList){
            $RelationshipReport += New-Object PSObject -Property @{
                ID = $ID
                ChildID = $Relationship.identIFier
                ResourceKind = $Relationship.resourceKey.resourceKindKey
                ResourceName = $Relationship.resourceKey.name
            }
        }
    }
    End{
        Return $RelationshipReport
    }
}