Skip to content

Commit 3a6d855

Browse files
authored
Merge pull request #308 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5f7d2eb + 40c164c commit 3a6d855

File tree

4 files changed

+145
-4
lines changed

4 files changed

+145
-4
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using namespace System.Net
2+
3+
Function Invoke-EditIntunePolicy {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Endpoint.MEM.Read
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Interact with query parameters or the body of the request.
18+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
19+
$ID = $Request.Query.ID ?? $Request.Body.ID
20+
$DisplayName = $Request.Query.newDisplayName ?? $Request.Body.newDisplayName
21+
$PolicyType = $Request.Query.policyType ?? $Request.Body.policyType
22+
23+
try {
24+
$properties = @{}
25+
26+
# Only add displayName if it's provided
27+
if ($DisplayName) {
28+
$properties["displayName"] = $DisplayName
29+
}
30+
31+
# Update the policy
32+
$Request = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$PolicyType/$ID" -tenantid $TenantFilter -type PATCH -body ($properties | ConvertTo-Json) -asapp $true
33+
34+
$Result = "Successfully updated Intune policy $($ID)"
35+
if ($DisplayName) { $Result += " name to '$($DisplayName)'" }
36+
37+
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Info'
38+
$StatusCode = [HttpStatusCode]::OK
39+
} catch {
40+
$ErrorMessage = Get-CippException -Exception $_
41+
$Result = "Failed to update Intune policy $($ID): $($ErrorMessage.NormalizedError)"
42+
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Error' -LogData $ErrorMessage
43+
$StatusCode = [HttpStatusCode]::InternalServerError
44+
}
45+
46+
# Associate values to output bindings by calling 'Push-OutputBinding'.
47+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
48+
StatusCode = $StatusCode
49+
Body = @{ 'Results' = $Result }
50+
})
51+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-EditPolicy.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Function Invoke-EditPolicy {
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
1212

13+
# Note, suspect this is deprecated - rvdwegen
14+
1315
$APIName = $Request.Params.CIPPEndpoint
1416
$Headers = $Request.Headers
1517
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-EditCAPolicy.ps1

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@ Function Invoke-EditCAPolicy {
1818
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1919
$ID = $Request.Query.GUID ?? $Request.Body.GUID
2020
$State = $Request.Query.State ?? $Request.Body.State
21+
$DisplayName = $Request.Query.newDisplayName ?? $Request.Body.newDisplayName
2122

2223
try {
23-
$EditBody = "{`"state`": `"$($State)`"}"
24-
$Request = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta//identity/conditionalAccess/policies/$($ID)" -tenantid $TenantFilter -type PATCH -body $EditBody -asapp $true
25-
$Result = "Successfully set CA policy $($ID) to $($State)"
24+
$properties = @{}
25+
26+
# Conditionally add properties
27+
if ($State) {
28+
$properties["state"] = $State
29+
}
30+
31+
if ($DisplayName) {
32+
$properties["displayName"] = $DisplayName
33+
}
34+
35+
$Request = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta//identity/conditionalAccess/policies/$($ID)" -tenantid $TenantFilter -type PATCH -body ($properties | ConvertTo-Json) -asapp $true
36+
37+
$Result = "Successfully updated CA policy $($ID)"
38+
if ($State) { $Result += " state to $($State)" }
39+
if ($DisplayName) { $Result += " name to '$($DisplayName)'" }
40+
2641
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Info'
2742
$StatusCode = [HttpStatusCode]::OK
2843
} catch {
2944
$ErrorMessage = Get-CippException -Exception $_
30-
$Result = "Failed to set CA policy $($ID) to $($State): $($ErrorMessage.NormalizedError)"
45+
$Result = "Failed to update CA policy $($ID): $($ErrorMessage.NormalizedError)"
3146
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Error' -LogData $ErrorMessage
3247
$StatusCode = [HttpStatusCode]::InternalServerError
3348
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function Invoke-CIPPStandardDefaultSharingLink {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) DefaultSharingLink
7+
.SYNOPSIS
8+
(Label) Set Default Sharing Link Settings
9+
.DESCRIPTION
10+
(Helptext) Sets the default sharing link type to Internal and permission to View in SharePoint and OneDrive.
11+
(DocsDescription) Sets the default sharing link type to Internal and permission to View in SharePoint and OneDrive.
12+
.NOTES
13+
CAT
14+
SharePoint Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
IMPACT
18+
Medium Impact
19+
ADDEDDATE
20+
2025-06-13
21+
POWERSHELLEQUIVALENT
22+
Set-SPOTenant -DefaultSharingLinkType Internal -DefaultLinkPermission View
23+
RECOMMENDEDBY
24+
UPDATECOMMENTBLOCK
25+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
26+
.LINK
27+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
28+
#>
29+
30+
param($Tenant, $Settings)
31+
32+
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
33+
Select-Object -Property DefaultSharingLinkType, DefaultLinkPermission
34+
35+
$StateIsCorrect = ($CurrentState.DefaultSharingLinkType -eq 2) -and ($CurrentState.DefaultLinkPermission -eq 1)
36+
37+
if ($Settings.remediate -eq $true) {
38+
if ($StateIsCorrect -eq $true) {
39+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are already configured correctly' -Sev Info
40+
} else {
41+
$Properties = @{
42+
DefaultSharingLinkType = 2 # Internal
43+
DefaultLinkPermission = 1 # View
44+
}
45+
46+
try {
47+
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
48+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set default sharing link settings' -Sev Info
49+
} catch {
50+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
51+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set default sharing link settings. Error: $ErrorMessage" -Sev Error
52+
}
53+
}
54+
}
55+
56+
if ($Settings.alert -eq $true) {
57+
if ($StateIsCorrect -eq $true) {
58+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are configured correctly' -Sev Info
59+
} else {
60+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are not configured correctly' -Sev Alert
61+
}
62+
}
63+
64+
if ($Settings.report -eq $true) {
65+
Add-CIPPBPAField -FieldName 'DefaultSharingLink' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
66+
if ($StateIsCorrect) {
67+
$FieldValue = $true
68+
} else {
69+
$FieldValue = $CurrentState
70+
}
71+
Set-CIPPStandardsCompareField -FieldName 'standards.DefaultSharingLink' -FieldValue $FieldValue -Tenant $Tenant
72+
}
73+
}

0 commit comments

Comments
 (0)