Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmitt-hbcg committed Feb 23, 2024
2 parents ec9601d + 2d8e766 commit 79a1244
Show file tree
Hide file tree
Showing 83 changed files with 1,553 additions and 933 deletions.
8 changes: 5 additions & 3 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-AddPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ Function Invoke-AddPolicy {
if ($PolicyName -in $CheckExististing.displayName) {
Throw "Policy with Display Name $($Displayname) Already exists"
}

$PolicyFile = $RawJSON | ConvertFrom-Json
$Null = $PolicyFile | Add-Member -MemberType NoteProperty -Name 'description' -Value $description -Force
$null = $PolicyFile | Add-Member -MemberType NoteProperty -Name 'displayName' -Value $displayname -Force
$RawJSON = ConvertTo-Json -InputObject $PolicyFile -Depth 20
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$TemplateTypeURL" -tenantid $tenant -type POST -body $RawJSON
}
'Catalog' {
Expand All @@ -62,8 +65,7 @@ Function Invoke-AddPolicy {
Set-CIPPAssignedPolicy -GroupName $AssignTo -PolicyId $CreateRequest.id -Type $TemplateTypeURL -TenantFilter $tenant
}
"Successfully added policy for $($Tenant)"
}
catch {
} catch {
"Failed to add policy for $($Tenant): $($_.Exception.Message)"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Failed adding policy $($Displayname). Error: $($_.Exception.Message)" -Sev 'Error'
continue
Expand Down
23 changes: 15 additions & 8 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-AddUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Function Invoke-AddUser {
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = "AddUser"
$APIName = 'AddUser'
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$Results = [System.Collections.ArrayList]@()
Expand Down Expand Up @@ -56,8 +56,7 @@ Function Invoke-AddUser {
$results.add('Created user.')
$results.add("Username: $($UserprincipalName)")
$results.add("Password: $password")
}
catch {
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($userobj.tenantid) -message "Failed to create user. Error:$($_.Exception.Message)" -Sev 'Error'
$body = $results.add("Failed to create user. $($_.Exception.Message)" )
}
Expand All @@ -70,8 +69,7 @@ Function Invoke-AddUser {
$LicenseBody = if ($licenses.count -ge 2) {
$liclist = foreach ($license in $Licenses) { '{"disabledPlans": [],"skuId": "' + $license + '" },' }
'{"addLicenses": [' + $LicList + '], "removeLicenses": [ ] }'
}
else {
} else {
'{"addLicenses": [ {"disabledPlans": [],"skuId": "' + $licenses + '" }],"removeLicenses": [ ]}'
}
Write-Host $LicenseBody
Expand All @@ -97,8 +95,7 @@ Function Invoke-AddUser {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($userobj.tenantid) -message "Added alias $($Alias) to $($userobj.displayname)" -Sev 'Info'
$body = $results.add("Added Aliases: $($Aliases -join ',')")
}
}
catch {
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($userobj.tenantid) -message "Failed to create the Aliases. Error:$($_.Exception.Message)" -Sev 'Error'
$body = $results.add("Failed to create the Aliases: $($_.Exception.Message)")
}
Expand All @@ -107,7 +104,15 @@ Function Invoke-AddUser {
$results.Add($CopyFrom.Success -join ', ')
$results.Add($CopyFrom.Error -join ', ')
}


if ($Request.body.setManager) {
$ManagerBody = [PSCustomObject]@{'@odata.id' = "https://graph.microsoft.com/beta/users/$($Request.body.setManager.value)" }
$ManagerBodyJSON = ConvertTo-Json -Compress -Depth 10 -InputObject $ManagerBody
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($GraphRequest.id)/manager/`$ref" -tenantid $Userobj.tenantid -type PUT -body $ManagerBodyJSON -Verbose
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $Userobj.tenantid -message "Set $($UserObj.DisplayName)'s manager to $($Request.body.setManager.label)" -Sev 'Info'
$results.add("Success. Set $($UserObj.DisplayName)'s manager to $($Request.body.setManager.label)")
}

$copyFromResults = @{
'Success' = $CopyFrom.Success
'Error' = $CopyFrom.Error
Expand All @@ -119,6 +124,8 @@ Function Invoke-AddUser {
'Password' = $password
'CopyFrom' = $copyFromResults
}


# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Expand Down
9 changes: 8 additions & 1 deletion Modules/CIPPCore/Public/Entrypoints/Invoke-EditUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ Function Invoke-EditUser {

}
}

if ($Request.body.setManager) {
$ManagerBody = [PSCustomObject]@{'@odata.id' = "https://graph.microsoft.com/beta/users/$($Request.body.setManager.value)" }
$ManagerBodyJSON = ConvertTo-Json -Compress -Depth 10 -InputObject $ManagerBody
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userobj.Userid)/manager/`$ref" -tenantid $Userobj.tenantid -type PUT -body $ManagerBodyJSON -Verbose
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $Userobj.tenantid -message "Set $($UserObj.DisplayName)'s manager to $($Request.body.setManager.label)" -Sev 'Info'
$results.add("Success. Set $($UserObj.DisplayName)'s manager to $($Request.body.setManager.label)")
}

if ($RemoveFromGroups) {
$RemoveFromGroups | ForEach-Object {

Expand Down
35 changes: 35 additions & 0 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ExecDeviceDelete.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using namespace System.Net

Function Invoke-ExecDeviceDelete {
<#
.FUNCTIONALITY
Entrypoint
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Interact with query parameters or the body of the request.


try {
$url = "https://graph.microsoft.com/beta/devices/$($request.query.id)"
if ($Request.query.action -eq 'delete') {
$ActionResult = New-GraphPOSTRequest -uri $url -type DELETE -tenantid $Request.Query.TenantFilter
} else {
$ActionResult = New-GraphPOSTRequest -uri $url -type PATCH -tenantid $Request.Query.TenantFilter -body '{"accountEnabled": false }'
}
$body = [pscustomobject]@{'Results' = "Executed action $($Request.query.action) on $($Request.query.id)" }
} catch {
$body = [pscustomobject]@{'Results' = "Failed to queue action $($Request.query.action) on $($request.query.id): $($_.Exception.Message)" }
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ Function Invoke-ExecGraphExplorerPreset {
$Id = (New-Guid).Guid
}
'Save' {
$Id = $Request.Body.values.reportTemplate.value
$Id = $Request.Body.preset.reportTemplate.value
}
'Delete' {
$Id = $Request.Body.values.reportTemplate.value
$Id = $Request.Body.preset.reportTemplate.value
}
default {
$Request.Body.Action = 'Copy'
$Id = (New-Guid).Guid
}
}

$params = $Request.Body.values | Select-Object endpoint, '$filter', '$select', '$count', '$expand', '$search', NoPagination, '$top', IsShared
$params = $Request.Body.preset | Select-Object endpoint, '$filter', '$select', '$count', '$expand', '$search', NoPagination, '$top', IsShared
$Preset = [PSCustomObject]@{
PartitionKey = 'Preset'
RowKey = [string]$Id
id = [string]$Id
name = [string]$Request.Body.values.name
name = [string]$Request.Body.preset.name
Owner = [string]$Username
IsShared = $Request.Body.values.IsShared
IsShared = $Request.Body.preset.IsShared
params = [string](ConvertTo-Json -InputObject $params -Compress)
}

Expand Down
Loading

0 comments on commit 79a1244

Please sign in to comment.