Functions/Public/Remove-vRATenantDirectory.psm1

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
function Remove-vRATenantDirectory {
<#
    .SYNOPSIS
    Remove a vRA Tenant Directory
    
    .DESCRIPTION
    Remove a vRA Tenant Directory
    
    .PARAMETER Id
    Tenant Id

    .PARAMETER Domain
    Tenant Directory Domain

    .INPUTS
    System.String.

    .OUTPUTS
    None

    .EXAMPLE
    Remove-vRATenantDirectory -Id Tenant01 -Domain vrademo.local
    
    .EXAMPLE
    $Id = "Tenant01"
    Get-vRATenantDirectory -Id $Id | Remove-vRATenantDirectory -Id $Id -Confirm:$false
#>

[CmdletBinding(SupportsShouldProcess,ConfirmImpact="High")]

    Param (

    [parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [String]$Id,

    [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [ValidateNotNullOrEmpty()]
    [String]$Domain
    )    

    begin {
    
    }
    
    process {    
            
        foreach ($TenantId in $Id){
                
            try {
                if ($PSCmdlet.ShouldProcess($Id)){

                    $URI = "/identity/api/tenants/$($ID)/directories/$($Domain)"  

                    # --- Run vRA REST Request
                    $Response = Invoke-vRARestMethod -Method DELETE -URI $URI
                }
            }
            catch [Exception]{

                throw
            } 
        }
    }
    end {
        
    }
}