-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from jakkulabs/feature-New-vRABusinessGroup-S…
…haredAccess Added SharedAccess parameter to New-vRABusinessGroup for issue #183
- Loading branch information
Showing
2 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
.PARAMETER SupportUser | ||
Business Group Support Users | ||
.PARAMETER SharedAccessUser | ||
Business Group Shared Access Users | ||
.PARAMETER User | ||
Business Group Users | ||
|
@@ -43,6 +46,10 @@ | |
New-vRABusinessGroup -TenantId Tenant01 -Name BusinessGroup01 -Description "Business Group 01" -BusinessGroupManager "[email protected]","[email protected]" -SupportUser "[email protected]" ` | ||
-User "[email protected]" -MachinePrefixId "87e99513-cbea-4589-8678-c84c5907bdf2" -SendManagerEmailsTo "[email protected]" | ||
.EXAMPLE | ||
New-vRABusinessGroup -TenantId Tenant01 -Name BusinessGroup02 -Description "Business Group 02" -BusinessGroupManager "[email protected]" -SharedAccessUser "[email protected]" ` | ||
-SendManagerEmailsTo "[email protected]" | ||
.EXAMPLE | ||
$JSON = @" | ||
{ | ||
|
@@ -129,6 +136,10 @@ | |
[ValidateNotNullOrEmpty()] | ||
[String[]]$SupportUser, | ||
|
||
[parameter(Mandatory=$false,ParameterSetName="Standard")] | ||
[ValidateNotNullOrEmpty()] | ||
[String[]]$SharedAccessUser, | ||
|
||
[parameter(Mandatory=$false,ParameterSetName="Standard")] | ||
[ValidateNotNullOrEmpty()] | ||
[String[]]$User, | ||
|
@@ -149,6 +160,15 @@ | |
begin { | ||
# --- Test for vRA API version | ||
xRequires -Version 7.0 | ||
|
||
# --- Test for API 7.3 if SharedAccessUser parameter specified | ||
if ($PSBoundParameters.ContainsKey("SharedAccessUser")){ | ||
|
||
if ($vRAConnection.APIVersion -lt 7.3){ | ||
|
||
throw "vRA BusinessGroup Shared Access feature requires vRA version 7.3 or greater" | ||
} | ||
} | ||
} | ||
|
||
process { | ||
|
@@ -205,10 +225,26 @@ | |
} | ||
"@ | ||
|
||
$BodySharedAccess = @" | ||
{ | ||
"name": "com.vmware.csp.core.cafe.identity@csp.scoperole.sharedaccess.user.name", | ||
"scopeRoleRef": "CSP_CONSUMER_WITH_SHARED_ACCESS", | ||
"principalId": [ | ||
] | ||
} | ||
"@ | ||
|
||
# --- If certain parameters are specified, ConvertFrom-Json, update, then ConvertTo-Json | ||
if ($PSBoundParameters.ContainsKey("BusinessGroupManager") -or $PSBoundParameters.ContainsKey("SupportUser") -or $PSBoundParameters.ContainsKey("User") -or $PSBoundParameters.ContainsKey("MachinePrefixId")){ | ||
if ($PSBoundParameters.ContainsKey("BusinessGroupManager") -or $PSBoundParameters.ContainsKey("SupportUser") -or $PSBoundParameters.ContainsKey("SharedAccessUser") -or $PSBoundParameters.ContainsKey("User") -or $PSBoundParameters.ContainsKey("MachinePrefixId")){ | ||
|
||
$JSONObject = $Body | ConvertFrom-Json | ||
|
||
# --- Add Shared Access feature from vRA 7.3 | ||
if ($vRAConnection.APIVersion -ge 7.3){ | ||
|
||
$JSONObject.subtenantRoles += ($BodySharedAccess | ConvertFrom-Json) | ||
} | ||
|
||
if ($PSBoundParameters.ContainsKey("BusinessGroupManager")){ | ||
|
||
|
@@ -230,7 +266,6 @@ | |
$BusinessGroupManagerRole.principalId += $AdditionObject | ||
|
||
} | ||
|
||
} | ||
|
||
if ($PSBoundParameters.ContainsKey("SupportUser")){ | ||
|
@@ -253,7 +288,28 @@ | |
$SupportUserRole.principalId += $AdditionObject | ||
|
||
} | ||
} | ||
|
||
if ($PSBoundParameters.ContainsKey("SharedAccessUser")){ | ||
|
||
foreach ($Entity in $SharedAccessUser){ | ||
|
||
$Domain = ($Entity -split "@")[1] | ||
$Username = ($Entity -split "@")[0] | ||
|
||
$Addition = @" | ||
{ | ||
"domain": "$($Domain)", | ||
"name": "$($Username)" | ||
} | ||
"@ | ||
|
||
$AdditionObject = $Addition | ConvertFrom-Json | ||
|
||
$SupportUserRole = $JSONObject.subtenantRoles | Where-Object {$_.Name -eq "com.vmware.csp.core.cafe.identity@csp.scoperole.sharedaccess.user.name"} | ||
$SupportUserRole.principalId += $AdditionObject | ||
|
||
} | ||
} | ||
|
||
if ($PSBoundParameters.ContainsKey("User")){ | ||
|
@@ -276,7 +332,6 @@ | |
$UserRole.principalId += $AdditionObject | ||
|
||
} | ||
|
||
} | ||
|
||
if ($PSBoundParameters.ContainsKey("MachinePrefixId")){ | ||
|