Skip to content

Commit 3609fe0

Browse files
authored
Merge pull request #9 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents c0cbd88 + 951cd47 commit 3609fe0

File tree

122 files changed

+800
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+800
-309
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertInactiveLicensedUsers.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ function Get-CIPPAlertInactiveLicensedUsers {
1515
try {
1616

1717
$Lookup = (Get-Date).AddDays(-90).ToUniversalTime().ToString('o')
18-
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=(signInActivity/lastNonInteractiveSignInDateTime le $Lookup)&`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled,assignedLicenses" -scope 'https://graph.microsoft.com/.default' -tenantid $TenantFilter | Where-Object { $_.assignedLicenses.skuId -ne $null }
18+
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=(signInActivity/lastNonInteractiveSignInDateTime le $Lookup)&`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled,assignedLicenses" -scope 'https://graph.microsoft.com/.default' -tenantid $TenantFilter |
19+
Where-Object { $null -ne $_.assignedLicenses.skuId }
20+
21+
# true = only active users
22+
if ($InputValue -eq $true) { $GraphRequest = $GraphRequest | Where-Object { $_.accountEnabled -eq $true } }
1923
$AlertData = foreach ($user in $GraphRequest) {
2024
$Message = 'User {0} has been inactive for 90 days, but still has a license assigned.' -f $user.UserPrincipalName
21-
$user | Select-Object -Property userPrincipalname, signInActivity, @{Name = 'Message'; Expression = { $Message } }
25+
$user | Select-Object -Property UserPrincipalName, signInActivity, @{Name = 'Message'; Expression = { $Message } }
2226

2327
}
2428
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Invoke-ExecHideFromGAL.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@ Function Invoke-ExecHideFromGAL {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $TriggerMetadata.FunctionName
14-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
14+
$ExecutingUser = $Request.headers.'x-ms-client-principal'
15+
$APIName = $TriggerMetadata.FunctionName
16+
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'
17+
18+
19+
# Support if the request is a POST or a GET. So to support legacy(GET) and new(POST) requests
20+
$UserId = $Request.Query.ID ?? $Request.body.ID
21+
$TenantFilter = $Request.Query.TenantFilter ?? $Request.body.tenantFilter
22+
$Hidden = -not [string]::IsNullOrWhiteSpace($Request.Query.HideFromGAL) ? [System.Convert]::ToBoolean($Request.Query.HideFromGAL) : [System.Convert]::ToBoolean($Request.body.HideFromGAL)
1523

1624

17-
$TenantFilter = $request.query.tenantfilter
1825
Try {
19-
$Hidden = [System.Convert]::ToBoolean($Request.query.HideFromGal)
20-
$HideResults = Set-CIPPHideFromGAL -tenantFilter $tenantFilter -userid $Request.query.ID -HideFromGAL $Hidden -ExecutingUser $request.headers.'x-ms-client-principal' -APIName 'ExecOffboardUser'
26+
$HideResults = Set-CIPPHideFromGAL -tenantFilter $TenantFilter -UserID $UserId -hidefromgal $Hidden -ExecutingUser $ExecutingUser -APIName $APIName
2127
$Results = [pscustomobject]@{'Results' = $HideResults }
28+
$StatusCode = [HttpStatusCode]::OK
2229

2330
} catch {
24-
$Results = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }
25-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($tenantfilter) -message "Hide/UnHide from GAL failed: $($_.Exception.Message)" -Sev 'Error'
31+
$ErrorMessage = Get-CippException -Exception $_
32+
$Results = [pscustomobject]@{'Results' = "Failed. $($ErrorMessage.NormalizedError)" }
33+
$StatusCode = [HttpStatusCode]::Forbidden
2634
}
2735
# Associate values to output bindings by calling 'Push-OutputBinding'.
2836
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
29-
StatusCode = [HttpStatusCode]::OK
37+
StatusCode = $StatusCode
3038
Body = $Results
3139
})
3240

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ListGlobalAddressList {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Exchange.Mailbox.Read
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
$ExecutingUser = $Request.headers.'x-ms-client-principal'
15+
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'
16+
$TenantFilter = $Request.Query.tenantFilter
17+
18+
try {
19+
$GAL = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-Recipient' -cmdParams @{ResultSize = 'unlimited'; SortBy = 'DisplayName' } `
20+
-Select 'Identity, DisplayName, Alias, PrimarySmtpAddress, ExternalDirectoryObjectId, HiddenFromAddressListsEnabled, EmailAddresses, IsDirSynced, SKUAssigned, RecipientType, RecipientTypeDetails, AddressListMembership' | Select-Object -ExcludeProperty *odata*, *data.type*
21+
$StatusCode = [HttpStatusCode]::OK
22+
} catch {
23+
$ErrorMessage = Get-CippException -Exception $_
24+
$StatusCode = [HttpStatusCode]::Forbidden
25+
$GAL = $ErrorMessage.NormalizedError
26+
}
27+
28+
# Associate values to output bindings by calling 'Push-OutputBinding'.
29+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
30+
StatusCode = $StatusCode
31+
Body = @($GAL)
32+
})
33+
34+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Devices/Invoke-ExecDeviceDelete.ps1

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,28 @@ Function Invoke-ExecDeviceDelete {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $TriggerMetadata.FunctionName
14-
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
15-
16-
# Interact with query parameters or the body of the request.
14+
$ExecutingUser = $Request.headers.'x-ms-client-principal'
15+
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1716

17+
# Interact with body parameters or the body of the request.
18+
$TenantFilter = $Request.body.tenantFilter ?? $Request.Query.tenantFilter
19+
$Action = $Request.body.action ?? $Request.Query.action
20+
$DeviceID = $Request.body.ID ?? $Request.Query.ID
1821

1922
try {
20-
$url = "https://graph.microsoft.com/beta/devices/$($request.query.id)"
21-
if ($Request.query.action -eq 'delete') {
22-
$ActionResult = New-GraphPOSTRequest -uri $url -type DELETE -tenantid $Request.Query.TenantFilter
23-
} elseif ($Request.query.action -eq 'disable') {
24-
$ActionResult = New-GraphPOSTRequest -uri $url -type PATCH -tenantid $Request.Query.TenantFilter -body '{"accountEnabled": false }'
25-
} elseif ($Request.query.action -eq 'enable') {
26-
$ActionResult = New-GraphPOSTRequest -uri $url -type PATCH -tenantid $Request.Query.TenantFilter -body '{"accountEnabled": true }'
27-
}
28-
Write-Host $ActionResult
29-
$body = [pscustomobject]@{'Results' = "Executed action $($Request.query.action) on $($Request.query.id)" }
23+
$Results = Set-CIPPDeviceState -Action $Action -DeviceID $DeviceID -TenantFilter $TenantFilter -ExecutingUser $ExecutingUser -APIName $APINAME
24+
$StatusCode = [HttpStatusCode]::OK
3025
} catch {
31-
$body = [pscustomobject]@{'Results' = "Failed to queue action $($Request.query.action) on $($request.query.id): $($_.Exception.Message)" }
26+
$Results = $_.Exception.Message
27+
$StatusCode = [HttpStatusCode]::BadRequest
3228
}
3329

30+
Write-Host $Results
31+
$body = [pscustomobject]@{'Results' = "$Results" }
32+
3433
# Associate values to output bindings by calling 'Push-OutputBinding'.
3534
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
36-
StatusCode = [HttpStatusCode]::OK
35+
StatusCode = $StatusCode
3736
Body = $body
3837
})
3938

Modules/CIPPCore/Public/Entrypoints/Invoke-ListIntuneTemplates.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Function Invoke-ListIntuneTemplates {
4848

4949
if ($Request.query.ID) { $Templates = $Templates | Where-Object -Property guid -EQ $Request.query.id }
5050

51+
# Sort all output regardless of view condition
52+
$Templates = $Templates | Sort-Object -Property displayName
5153

5254
# Associate values to output bindings by calling 'Push-OutputBinding'.
5355
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

Modules/CIPPCore/Public/New-CIPPBackup.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function New-CIPPBackup {
2121
'standards'
2222
'SchedulerConfig'
2323
'Extensions'
24+
'WebhookRules'
25+
'ScheduledTasks'
2426
)
2527
$CSVfile = foreach ($CSVTable in $BackupTables) {
2628
$Table = Get-CippTable -tablename $CSVTable
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
function Set-CIPPDeviceState {
2+
<#
3+
.SYNOPSIS
4+
Sets or modifies the state of a device in Microsoft Graph.
5+
6+
.DESCRIPTION
7+
This function allows you to enable, disable, or delete a device by making
8+
corresponding requests to the Microsoft Graph API. It logs the result
9+
and returns a success or error message based on the outcome.
10+
11+
.PARAMETER Action
12+
Specifies the action to perform on the device. Valid actions are:
13+
- Enable: Enable the device
14+
- Disable: Disable the device
15+
- Delete: Remove the device from the tenant
16+
17+
.PARAMETER DeviceID
18+
Specifies the unique identifier (Object ID) of the device to be managed.
19+
20+
.PARAMETER TenantFilter
21+
Specifies the tenant ID or domain against which to perform the operation.
22+
23+
.PARAMETER ExecutingUser
24+
Specifies the user who initiated the request for logging purposes.
25+
26+
.PARAMETER APIName
27+
Specifies the name of the API call for logging purposes. Defaults to 'Set Device State'.
28+
29+
.EXAMPLE
30+
Set-CIPPDeviceState -Action Enable -DeviceID "1234abcd-5678-efgh-ijkl-9012mnopqrst" -TenantFilter "contoso.onmicrosoft.com" -ExecutingUser "[email protected]"
31+
32+
This command enables the specified device within the given tenant.
33+
34+
.EXAMPLE
35+
Set-CIPPDeviceState -Action Delete -DeviceID "1234abcd-5678-efgh-ijkl-9012mnopqrst" -TenantFilter "contoso.onmicrosoft.com"
36+
37+
This command removes the specified device from the tenant.
38+
#>
39+
param (
40+
[Parameter(Mandatory = $true)][ValidateSet('Enable', 'Disable', 'Delete')]$Action,
41+
42+
[ValidateScript({
43+
if ([Guid]::TryParse($_, [ref] [Guid]::Empty)) {
44+
$true
45+
} else {
46+
throw 'DeviceID must be a valid GUID.'
47+
}
48+
})]
49+
[Parameter(Mandatory = $true)]$DeviceID,
50+
51+
[Parameter(Mandatory = $true)]$TenantFilter,
52+
$ExecutingUser,
53+
$APIName = 'Set Device State'
54+
)
55+
$Url = "https://graph.microsoft.com/beta/devices/$($DeviceID)"
56+
57+
try {
58+
switch ($Action) {
59+
'Delete' {
60+
$ActionResult = New-GraphPOSTRequest -uri $Url -type DELETE -tenantid $TenantFilter
61+
}
62+
'Disable' {
63+
$ActionResult = New-GraphPOSTRequest -uri $Url -type PATCH -tenantid $TenantFilter -body '{"accountEnabled": false }'
64+
}
65+
'Enable' {
66+
$ActionResult = New-GraphPOSTRequest -uri $Url -type PATCH -tenantid $TenantFilter -body '{"accountEnabled": true }'
67+
}
68+
}
69+
Write-Host $ActionResult
70+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Executed action $($Action) on $($DeviceID)" -Sev Info
71+
return "Executed action $($Action) on $($DeviceID)"
72+
} catch {
73+
$ErrorMessage = Get-CippException -Exception $_
74+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Failed to queue action $($Action) on $($DeviceID). Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
75+
throw "Failed to queue action $($Action) on $($DeviceID). Error: $($ErrorMessage.NormalizedError)"
76+
}
77+
78+
79+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
function Set-CIPPHideFromGAL {
22
[CmdletBinding()]
33
param (
4-
$userid,
5-
$tenantFilter,
4+
$UserId,
5+
$TenantFilter,
66
$APIName = 'Hide From Address List',
77
[bool]$HideFromGAL,
88
$ExecutingUser
99
)
1010
$Text = if ($HideFromGAL) { 'hidden' } else { 'unhidden' }
1111
try {
12-
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $userid ; HiddenFromAddressListsEnabled = $HideFromGAL }
13-
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $($tenantfilter) -message "$($userid) $Text from GAL" -Sev 'Info'
14-
return "Successfully $Text $($userid) from GAL."
12+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams @{Identity = $UserId ; HiddenFromAddressListsEnabled = $HideFromGAL }
13+
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $($Tenantfilter) -message "$($UserId) $Text from GAL" -Sev Info
14+
return "Successfully $Text $($UserId) from GAL."
1515
} catch {
1616
$ErrorMessage = Get-CippException -Exception $_
17-
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not hide $($userid) from address list. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
18-
return "Could not hide $($userid) from address list. Error: $($ErrorMessage.NormalizedError)"
17+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not hide $($UserId) from address list. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
18+
return "Could not hide $($UserId) from address list. Error: $($ErrorMessage.NormalizedError)"
1919
}
2020
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardActivityBasedTimeout.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Invoke-CIPPStandardActivityBasedTimeout {
1717
"CIS"
1818
"spo_idle_session_timeout"
1919
ADDEDCOMPONENT
20-
{"type":"Select","label":"Select value","name":"standards.ActivityBasedTimeout.timeout","values":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
20+
{"type":"select","multiple":false,"label":"Select value","name":"standards.ActivityBasedTimeout.timeout","options":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
2121
IMPACT
2222
Medium Impact
2323
POWERSHELLEQUIVALENT
@@ -27,7 +27,7 @@ function Invoke-CIPPStandardActivityBasedTimeout {
2727
UPDATECOMMENTBLOCK
2828
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2929
.LINK
30-
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
30+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#medium-impact
3131
#>
3232

3333
param($Tenant, $Settings)

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAddDKIM.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Invoke-CIPPStandardAddDKIM {
2525
UPDATECOMMENTBLOCK
2626
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2727
.LINK
28-
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
28+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#low-impact
2929
#>
3030

3131
param($Tenant, $Settings)

0 commit comments

Comments
 (0)