forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
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 KelvinTegelaar#411 from KelvinTegelaar/dev
Dev to release
- Loading branch information
Showing
30 changed files
with
336 additions
and
198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,54 +8,10 @@ Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME - | |
|
||
$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value | ||
if ("AllTenants" -in $Tenants) { $Tenants = (Get-Tenants).defaultDomainName } | ||
$displayname = ($request.body.RawJSON | ConvertFrom-Json).Displayname | ||
function Remove-EmptyArrays ($Object) { | ||
if ($Object -is [Array]) { | ||
foreach ($Item in $Object) { Remove-EmptyArrays $Item } | ||
} | ||
elseif ($Object -is [HashTable]) { | ||
foreach ($Key in @($Object.get_Keys())) { | ||
if ($Object[$Key] -is [Array] -and $Object[$Key].get_Count() -eq 0) { | ||
$Object.Remove($Key) | ||
} | ||
else { Remove-EmptyArrays $Object[$Key] } | ||
} | ||
} | ||
elseif ($Object -is [PSCustomObject]) { | ||
foreach ($Name in @($Object.psobject.properties.Name)) { | ||
if ($Object.$Name -is [Array] -and $Object.$Name.get_Count() -eq 0) { | ||
$Object.PSObject.Properties.Remove($Name) | ||
} | ||
elseif ($object.$name -eq $null) { | ||
$Object.PSObject.Properties.Remove($Name) | ||
} | ||
else { Remove-EmptyArrays $Object.$Name } | ||
} | ||
} | ||
} | ||
|
||
$JSONObj = $request.body.RawJSON | ConvertFrom-Json | Select-Object * -ExcludeProperty ID, GUID, *time* | ||
Remove-EmptyArrays $JSONObj | ||
#Remove context as it does not belong in the payload. | ||
$JsonObj.grantControls.PSObject.Properties.Remove('[email protected]') | ||
if ($JSONObj.conditions.users.excludeGuestsOrExternalUsers.externalTenants.Members) { | ||
$JsonObj.conditions.users.excludeGuestsOrExternalUsers.externalTenants.PSObject.Properties.Remove('@odata.context') | ||
$JsonObj.conditions.users.excludeGuestsOrExternalUsers.externalTenants.PSObject.Properties.Remove('@odata.type') | ||
} | ||
if ($Request.body.newstate -and $Request.body.newstate -ne 'donotchange') { | ||
$Jsonobj.state = $Request.body.newstate | ||
} | ||
$RawJSON = $JSONObj | ConvertTo-Json -Depth 10 | ||
|
||
$results = foreach ($Tenant in $tenants) { | ||
try { | ||
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies" -tenantid $tenant | ||
$PolicyName = ($RawJSON | ConvertFrom-Json).displayName | ||
if ($PolicyName -in $CheckExististing.displayName) { | ||
Throw "Conditional Access Policy with Display Name $($Displayname) Already exists" | ||
} | ||
|
||
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies" -tenantid $tenant -type POST -body $RawJSON | ||
$CAPolicy = New-CIPPCAPolicy -TenantFilter $tenant -state $request.body.NewState -RawJSON $Request.body.RawJSON -APIName $APIName -ExecutingUser $request.headers.'x-ms-client-principal' | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Added Conditional Access Policy $($Displayname)" -Sev "Error" | ||
"Successfully added Conditional Access Policy for $($Tenant)" | ||
} | ||
|
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
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
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
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
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
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
Oops, something went wrong.