Skip to content

Commit 189ccf0

Browse files
Merge pull request KelvinTegelaar#1539 from kris6673/fix-SP-standards-speed
Feat: Speed up SP standards and deprecate SPDirectSharing
2 parents f0fa09c + 57fec34 commit 189ccf0

7 files changed

+56
-24
lines changed

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

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ function Invoke-CIPPStandardDefaultSharingLink {
77
.SYNOPSIS
88
(Label) Set Default Sharing Link Settings
99
.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.
10+
(Helptext) Configure the SharePoint default sharing link type and permission. This setting controls both the type of sharing link created by default and the permission level assigned to those links.
11+
(DocsDescription) Sets the default sharing link type (Direct or Internal) and permission (View) in SharePoint and OneDrive. Direct sharing means links only work for specific people, while Internal sharing means links work for anyone in the organization.
1212
.NOTES
1313
CAT
1414
SharePoint Standards
1515
TAG
1616
ADDEDCOMPONENT
17+
[{"type":"autoComplete","multiple":false,"creatable":false,"label":"Default Sharing Link Type","name":"standards.DefaultSharingLink.SharingLinkType","options":[{"label":"Direct - Only specific people","value":"Direct"},{"label":"Internal - Anyone in the organization","value":"Internal"}]}]
1718
IMPACT
1819
Medium Impact
1920
ADDEDDATE
2021
2025-06-13
2122
POWERSHELLEQUIVALENT
22-
Set-SPOTenant -DefaultSharingLinkType Internal -DefaultLinkPermission View
23+
Set-SPOTenant -DefaultSharingLinkType [Direct|Internal] -DefaultLinkPermission View
2324
RECOMMENDEDBY
25+
CIS
2426
UPDATECOMMENTBLOCK
2527
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2628
.LINK
@@ -29,35 +31,63 @@ function Invoke-CIPPStandardDefaultSharingLink {
2931

3032
param($Tenant, $Settings)
3133

34+
# Determine the desired sharing link type (default to Internal if not specified)
35+
$DesiredSharingLinkType = $Settings.SharingLinkType.value ?? 'Internal'
36+
37+
# Map the string values to numeric values for SharePoint
38+
$SharingLinkTypeMap = @{
39+
'Direct' = 1
40+
'Internal' = 2
41+
'Anyone' = 3
42+
}
43+
$DesiredSharingLinkTypeValue = $SharingLinkTypeMap[$DesiredSharingLinkType]
44+
3245
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
33-
Select-Object -Property DefaultSharingLinkType, DefaultLinkPermission
46+
Select-Object -Property _ObjectIdentity_, TenantFilter, DefaultSharingLinkType, DefaultLinkPermission
3447

35-
$StateIsCorrect = ($CurrentState.DefaultSharingLinkType -eq 2) -and ($CurrentState.DefaultLinkPermission -eq 1)
48+
# Check if the current state matches the desired configuration
49+
$StateIsCorrect = ($CurrentState.DefaultSharingLinkType -eq $DesiredSharingLinkTypeValue) -and ($CurrentState.DefaultLinkPermission -eq 1)
3650

3751
if ($Settings.remediate -eq $true) {
3852
if ($StateIsCorrect -eq $true) {
39-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are already configured correctly' -Sev Info
53+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Default sharing link settings are already configured correctly (Type: $DesiredSharingLinkType, Permission: View)" -Sev Info
4054
} else {
4155
$Properties = @{
42-
DefaultSharingLinkType = 2 # Internal
56+
DefaultSharingLinkType = $DesiredSharingLinkTypeValue
4357
DefaultLinkPermission = 1 # View
4458
}
4559

4660
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
61+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
62+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Successfully set default sharing link settings (Type: $DesiredSharingLinkType, Permission: View)" -Sev Info
4963
} 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
64+
$ErrorMessage = Get-CippException -Exception $_
65+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set default sharing link settings. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
5266
}
5367
}
5468
}
5569

5670
if ($Settings.alert -eq $true) {
5771
if ($StateIsCorrect -eq $true) {
58-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are configured correctly' -Sev Info
72+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Default sharing link settings are configured correctly (Type: $DesiredSharingLinkType, Permission: View)" -Sev Info
5973
} else {
60-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Default sharing link settings are not configured correctly' -Sev Alert
74+
# Determine current values for alert message
75+
$CurrentSharingType = switch ($CurrentState.DefaultSharingLinkType) {
76+
1 { 'Direct' }
77+
2 { 'Internal' }
78+
3 { 'Anyone' }
79+
default { 'Unknown' }
80+
}
81+
$CurrentPermission = switch ($CurrentState.DefaultLinkPermission) {
82+
0 { 'Edit' }
83+
1 { 'View' }
84+
2 { 'Edit' }
85+
default { 'Unknown' }
86+
}
87+
88+
$Message = "Default sharing link settings are not configured correctly. Current: Type=$CurrentSharingType, Permission=$CurrentPermission. Expected: Type=$DesiredSharingLinkType, Permission=View"
89+
Write-StandardsAlert -message $Message -object $CurrentState -tenant $Tenant -standardName 'DefaultSharingLink' -standardId $Settings.standardId
90+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message $Message -Sev Alert
6191
}
6292
}
6393

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Invoke-CIPPStandardSPAzureB2B {
3232
param($Tenant, $Settings)
3333

3434
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
35-
Select-Object -Property EnableAzureADB2BIntegration
35+
Select-Object -Property _ObjectIdentity_, TenantFilter, EnableAzureADB2BIntegration
3636

3737
$StateIsCorrect = ($CurrentState.EnableAzureADB2BIntegration -eq $true)
3838

@@ -45,7 +45,7 @@ function Invoke-CIPPStandardSPAzureB2B {
4545
}
4646

4747
try {
48-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
48+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
4949
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set the SharePoint Azure B2B to enabled' -Sev Info
5050
} catch {
5151
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ function Invoke-CIPPStandardSPDirectSharing {
3232

3333
param($Tenant, $Settings)
3434

35+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'This standard has been deprecated in favor of the "Set Default Sharing Link Settings" standard. Please update your standards to use new standard. However this will continue to function.' -Sev Alert
36+
3537
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
36-
Select-Object -Property DefaultSharingLinkType
38+
Select-Object -Property _ObjectIdentity_, TenantFilter, DefaultSharingLinkType
3739

3840
$StateIsCorrect = ($CurrentState.DefaultSharingLinkType -eq 'Direct' -or $CurrentState.DefaultSharingLinkType -eq 1)
3941

@@ -46,7 +48,7 @@ function Invoke-CIPPStandardSPDirectSharing {
4648
}
4749

4850
try {
49-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
51+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
5052
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set the SharePoint Default Direct Sharing to Direct' -Sev Info
5153
} catch {
5254
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Invoke-CIPPStandardSPDisableLegacyWorkflows {
4646
}
4747

4848
try {
49-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
49+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
5050
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully disabled Legacy Workflows' -Sev Info
5151
} catch {
5252
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Invoke-CIPPStandardSPDisallowInfectedFiles {
3333
param($Tenant, $Settings)
3434

3535
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
36-
Select-Object -Property DisallowInfectedFileDownload
36+
Select-Object -Property _ObjectIdentity_, TenantFilter, DisallowInfectedFileDownload
3737

3838
$StateIsCorrect = ($CurrentState.DisallowInfectedFileDownload -eq $true)
3939

@@ -46,7 +46,7 @@ function Invoke-CIPPStandardSPDisallowInfectedFiles {
4646
}
4747

4848
try {
49-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
49+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
5050
Write-LogMessage -API 'Standards' -tenant $tenant -Message 'Successfully disallowed downloading SharePoint infected files.' -Sev Info
5151
} catch {
5252
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Invoke-CIPPStandardSPEmailAttestation {
3333

3434
param($Tenant, $Settings)
3535

36-
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object -Property EmailAttestationReAuthDays, EmailAttestationRequired
36+
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object -Property _ObjectIdentity_, TenantFilter, EmailAttestationReAuthDays, EmailAttestationRequired
3737

3838
$StateIsCorrect = ($CurrentState.EmailAttestationReAuthDays -eq [int]$Settings.Days) -and
3939
($CurrentState.EmailAttestationRequired -eq $true)
@@ -48,7 +48,7 @@ function Invoke-CIPPStandardSPEmailAttestation {
4848
}
4949

5050
try {
51-
$Response = Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
51+
$Response = $CurrentState | Set-CIPPSPOTenant -Properties $Properties
5252
if ($Response.ErrorInfo.ErrorMessage) {
5353
$ErrorMessage = Get-NormalizedError -Message $Response.ErrorInfo.ErrorMessage
5454
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set re-authentication with verification code restriction. Error: $ErrorMessage" -Sev Error

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Invoke-CIPPStandardSPExternalUserExpiration {
3333
param($Tenant, $Settings)
3434

3535
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant |
36-
Select-Object -Property ExternalUserExpireInDays, ExternalUserExpirationRequired
36+
Select-Object -Property _ObjectIdentity_, TenantFilter, ExternalUserExpireInDays, ExternalUserExpirationRequired
3737

3838
$StateIsCorrect = ($CurrentState.ExternalUserExpireInDays -eq $Settings.Days) -and
3939
($CurrentState.ExternalUserExpirationRequired -eq $true)
@@ -48,7 +48,7 @@ function Invoke-CIPPStandardSPExternalUserExpiration {
4848
}
4949

5050
try {
51-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
51+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
5252
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set External User Expiration' -Sev Info
5353
} catch {
5454
$ErrorMessage = Get-CippException -Exception $_

0 commit comments

Comments
 (0)