Skip to content

Commit 40c164c

Browse files
author
rvdwegen
committed
Add standard to set default SP & Onedrive sharing #4234
1 parent 30069dc commit 40c164c

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
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)