Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#485 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
Dev to release
  • Loading branch information
KelvinTegelaar authored Nov 20, 2023
2 parents 1c1f118 + 0e4da13 commit 95be57e
Show file tree
Hide file tree
Showing 68 changed files with 998 additions and 572 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/dev_cippb2p4g.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/workflows/powershell-analysis.yml

This file was deleted.

15 changes: 10 additions & 5 deletions AddGroup/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ $results = foreach ($tenant in $SelectedTenants) {
try {
$email = if ($groupobj.domain) { "$($groupobj.username)@$($groupobj.domain)" } else { "$($groupobj.username)@$($tenant)" }
if ($groupobj.groupType -in "Generic", "azurerole", "dynamic") {

$BodyToship = [pscustomobject] @{
"displayName" = $groupobj.Displayname
"description" = $groupobj.Description
"mailNickname" = $groupobj.username
mailEnabled = [bool]$false
securityEnabled = [bool]$true
isAssignableToRole = [bool]($groupobj | Where-Object -Property groupType -EQ "AzureRole")

}
}
if ($groupobj.membershipRules) {
$BodyToship | Add-Member -NotePropertyName "membershipRule" -NotePropertyValue ($groupobj.membershipRules)
$BodyToship | Add-Member -NotePropertyName "groupTypes" -NotePropertyValue @("DynamicMembership")
$BodyToship | Add-Member -NotePropertyName "membershipRuleProcessingState" -NotePropertyValue "On"
}
if ($groupobj.AddOwner -AND $groupobj.groupType -in "generic", "azurerole", "security") {
$BodyToship | Add-Member -NotePropertyName "[email protected]" -NotePropertyValue (($groupobj.AddOwner) | ForEach-Object { "https://graph.microsoft.com/v1.0/users/$($_.value)" })
}
if ($groupobj.AddMember -AND $groupobj.groupType -in "generic", "azurerole", "security") {
$BodyToship | Add-Member -NotePropertyName "[email protected]" -NotePropertyValue (($groupobj.AddMember) | ForEach-Object { "https://graph.microsoft.com/v1.0/users/$($_.value)" })
}
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups" -tenantid $tenant -type POST -body (ConvertTo-Json -InputObject $BodyToship -Depth 10) -verbose
}
else {
Expand All @@ -43,6 +48,7 @@ $results = foreach ($tenant in $SelectedTenants) {
RequireSenderAuthenticationEnabled = [bool]!$groupobj.AllowExternal
}
$GraphRequest = New-ExoRequest -tenantid $tenant -cmdlet "New-DistributionGroup" -cmdParams $params
# At some point add logic to use AddOwner/AddMember for New-DistributionGroup, but idk how we're going to brr that - rvdwegen
}
"Successfully created group $($groupobj.displayname) for $($tenant)"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Created group $($groupobj.displayname) with id $($GraphRequest.id) " -Sev "Info"
Expand All @@ -51,7 +57,6 @@ $results = foreach ($tenant in $SelectedTenants) {
catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Group creation API failed. $($_.Exception.Message)" -Sev "Error"
"Failed to create group. $($groupobj.displayname) for $($tenant) $($_.Exception.Message)"

}
}
$body = [pscustomobject]@{"Results" = @($results) }
Expand All @@ -60,4 +65,4 @@ $body = [pscustomobject]@{"Results" = @($results) }
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Body
})
})
50 changes: 2 additions & 48 deletions AddScheduledItem/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,8 @@ using namespace System.Net
param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$task = $Request.Body
$Table = Get-CIPPTable -TableName 'ScheduledTasks'

$propertiesToCheck = @('Webhook', 'Email', 'PSA')
$PostExecution = ($propertiesToCheck | Where-Object { $task.PostExecution.$_ -eq $true }) -join ','

$Parameters = [System.Collections.Hashtable]@{}
foreach ($Key in $task.Parameters.Keys) {
$Param = $task.Parameters.$Key
if ($Param.Key) {
$ht = @{}
foreach ($p in $Param) {
Write-Host $p.Key
$ht[$p.Key] = $p.Value
}
$Parameters[$Key] = [PSCustomObject]$ht
} else {
$Parameters[$Key] = $Param
}
}

$Parameters = ($Parameters | ConvertTo-Json -Compress)

$AdditionalProperties = [System.Collections.Hashtable]@{}
foreach ($Prop in $task.AdditionalProperties) {
$AdditionalProperties[$Prop.Key] = $Prop.Value
}
$AdditionalProperties = ([PSCustomObject]$AdditionalProperties | ConvertTo-Json -Compress)


if ($Parameters -eq 'null') { $Parameters = '' }
$entity = @{
PartitionKey = [string]'ScheduledTask'
TaskState = [string]'Planned'
RowKey = [string]"$(New-Guid)"
Tenant = [string]$task.TenantFilter
Name = [string]$task.Name
Command = [string]$task.Command.value
Parameters = [string]$Parameters
ScheduledTime = [string]$task.ScheduledTime
Recurrence = [string]$task.Recurrence.value
PostExecution = [string]$PostExecution
AdditionalProperties = [string]$AdditionalProperties
Results = 'Planned'
}
Write-Host "entity: $($entity | ConvertTo-Json)"
Add-CIPPAzDataTableEntity @Table -Entity $entity
$Result = Add-CIPPScheduledTask -Task $Request.body -hidden $false
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ Results = 'Task added successfully.' }
Body = @{ Results = $Result }
})
2 changes: 1 addition & 1 deletion AddTransportRule/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object -Property * -ExcludeProperty GUID, Comments
$RequestParams = $Request.Body.PowerShellCommand | ConvertFrom-Json | Select-Object -Property * -ExcludeProperty GUID, Comments, HasSenderOverride, ExceptIfHasSenderOverride, ExceptIfMessageContainsDataClassifications, MessageContainsDataClassifications

$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value
$Result = foreach ($Tenantfilter in $tenants) {
Expand Down
10 changes: 8 additions & 2 deletions AddUser/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ catch {
}
if ($Request.body.CopyFrom -ne "") {
$CopyFrom = Set-CIPPCopyGroupMembers -ExecutingUser $request.headers.'x-ms-client-principal' -tenantid $Userobj.tenantid -CopyFromId $Request.body.CopyFrom -UserID $UserprincipalName -TenantFilter $Userobj.tenantid
$results.AddRange($CopyFrom)
$results.Add($CopyFrom.Success -join ', ')
$results.Add($CopyFrom.Error -join ', ')
}
$body = [pscustomobject] @{
"Results" = @($results)
"Username" = $UserprincipalName
"Password" = $password
"CopyFrom" = $CopyFrom
}
$body = @{"Results" = @($results) }
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Expand Down
Loading

0 comments on commit 95be57e

Please sign in to comment.