Skip to content

Commit a2d86cc

Browse files
committed
Add Invoke-CIPPStandardSPFileRequests function
Introduces a new PowerShell function to enable or disable SharePoint and OneDrive File Requests, including optional configuration for link expiration. The function supports remediation, alerting, and reporting, and includes license checks and input validation.
1 parent 3c432bb commit a2d86cc

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
function Invoke-CIPPStandardSPFileRequests {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) SPFileRequests
7+
.SYNOPSIS
8+
(Label) Set SharePoint and OneDrive File Requests
9+
.DESCRIPTION
10+
(Helptext) Enables or disables File Requests for SharePoint and OneDrive, allowing users to create secure upload-only links. Optionally sets the maximum number of days for the link to remain active.
11+
(DocsDescription) File Requests allow users to create secure upload-only share links where uploads are hidden from other people using the link. This creates a secure and private way for people to upload files to a folder. This standard enables or disables this feature and optionally configures link expiration settings.
12+
.NOTES
13+
CAT
14+
SharePoint Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
{"type":"switch","name":"standards.SPFileRequests.state","label":"Enable File Requests"}
18+
{"type":"number","name":"standards.SPFileRequests.expirationDays","label":"Link Expiration Days (Optional - 1-730)","required":false}
19+
IMPACT
20+
Medium Impact
21+
ADDEDDATE
22+
2025-07-30
23+
POWERSHELLEQUIVALENT
24+
Set-SPOTenant -CoreRequestFilesLinkEnabled \$true -OneDriveRequestFilesLinkEnabled \$true -CoreRequestFilesLinkExpirationInDays 30 -OneDriveRequestFilesLinkExpirationInDays 30
25+
RECOMMENDEDBY
26+
"CIPP"
27+
UPDATECOMMENTBLOCK
28+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
29+
.LINK
30+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
31+
#>
32+
33+
param($Tenant, $Settings)
34+
$TestResult = Test-CIPPStandardLicense -StandardName 'SPFileRequests' -TenantFilter $Tenant -RequiredCapabilities @('SHAREPOINTWAC', 'SHAREPOINTSTANDARD', 'SHAREPOINTENTERPRISE', 'ONEDRIVE_BASIC', 'ONEDRIVE_ENTERPRISE')
35+
36+
if ($TestResult -eq $false) {
37+
Write-Host "We're exiting as the correct license is not present for this standard."
38+
return $true
39+
}
40+
41+
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object _ObjectIdentity_, TenantFilter, CoreRequestFilesLinkEnabled, OneDriveRequestFilesLinkEnabled, CoreRequestFilesLinkExpirationInDays, OneDriveRequestFilesLinkExpirationInDays
42+
43+
# Input validation
44+
if (($Settings.state -eq $null) -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
45+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SPFileRequests: Invalid state parameter set' -sev Error
46+
return
47+
}
48+
49+
$WantedState = $Settings.state
50+
$ExpirationDays = $Settings.expirationDays
51+
$HumanReadableState = if ($WantedState -eq $true) { 'enabled' } else { 'disabled' }
52+
53+
# Check if current state matches desired state
54+
$CoreStateIsCorrect = if ($CurrentState.CoreRequestFilesLinkEnabled -eq $WantedState) { $true } else { $false }
55+
$OneDriveStateIsCorrect = if ($CurrentState.OneDriveRequestFilesLinkEnabled -eq $WantedState) { $true } else { $false }
56+
$StateIsCorrect = $CoreStateIsCorrect -and $OneDriveStateIsCorrect
57+
58+
# Check expiration settings if specified
59+
$ExpirationIsCorrect = $true
60+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
61+
$CoreExpirationIsCorrect = ($CurrentState.CoreRequestFilesLinkExpirationInDays -eq $ExpirationDays)
62+
$OneDriveExpirationIsCorrect = ($CurrentState.OneDriveRequestFilesLinkExpirationInDays -eq $ExpirationDays)
63+
$ExpirationIsCorrect = $CoreExpirationIsCorrect -and $OneDriveExpirationIsCorrect
64+
}
65+
66+
$AllSettingsCorrect = $StateIsCorrect -and $ExpirationIsCorrect
67+
68+
if ($Settings.remediate -eq $true) {
69+
Write-Host 'Time to remediate'
70+
71+
if ($AllSettingsCorrect -eq $false) {
72+
try {
73+
$Properties = @{
74+
CoreRequestFilesLinkEnabled = $WantedState
75+
OneDriveRequestFilesLinkEnabled = $WantedState
76+
}
77+
78+
# Add expiration settings if specified and feature is being enabled
79+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
80+
$Properties['CoreRequestFilesLinkExpirationInDays'] = $ExpirationDays
81+
$Properties['OneDriveRequestFilesLinkExpirationInDays'] = $ExpirationDays
82+
}
83+
84+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
85+
86+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
87+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set File Requests to $HumanReadableState$ExpirationMessage" -sev Info
88+
} catch {
89+
$ErrorMessage = Get-CippException -Exception $_
90+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set File Requests to $HumanReadableState. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
91+
}
92+
} else {
93+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
94+
Write-LogMessage -API 'Standards' -tenant $tenant -message "File Requests are already set to the wanted state of $HumanReadableState$ExpirationMessage" -sev Info
95+
}
96+
}
97+
98+
if ($Settings.alert -eq $true) {
99+
if ($AllSettingsCorrect -eq $true) {
100+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
101+
Write-LogMessage -API 'Standards' -tenant $tenant -message "File Requests are already set to the wanted state of $HumanReadableState$ExpirationMessage" -sev Info
102+
} else {
103+
$AlertMessage = "File Requests are not set to the wanted state of $HumanReadableState"
104+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
105+
$AlertMessage += " with $ExpirationDays day expiration"
106+
}
107+
Write-StandardsAlert -message $AlertMessage -object $CurrentState -tenant $tenant -standardName 'SPFileRequests' -standardId $Settings.standardId
108+
Write-LogMessage -API 'Standards' -tenant $tenant -message $AlertMessage -sev Info
109+
}
110+
}
111+
112+
if ($Settings.report -eq $true) {
113+
Add-CIPPBPAField -FieldName 'SPFileRequestsEnabled' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
114+
Add-CIPPBPAField -FieldName 'SPCoreFileRequestsEnabled' -FieldValue $CurrentState.CoreRequestFilesLinkEnabled -StoreAs bool -Tenant $Tenant
115+
Add-CIPPBPAField -FieldName 'SPOneDriveFileRequestsEnabled' -FieldValue $CurrentState.OneDriveRequestFilesLinkEnabled -StoreAs bool -Tenant $Tenant
116+
117+
if ($ExpirationDays -ne $null) {
118+
Add-CIPPBPAField -FieldName 'SPCoreFileRequestsExpirationDays' -FieldValue $CurrentState.CoreRequestFilesLinkExpirationInDays -StoreAs string -Tenant $Tenant
119+
Add-CIPPBPAField -FieldName 'SPOneDriveFileRequestsExpirationDays' -FieldValue $CurrentState.OneDriveRequestFilesLinkExpirationInDays -StoreAs string -Tenant $Tenant
120+
}
121+
122+
if ($AllSettingsCorrect) {
123+
$FieldValue = $true
124+
} else {
125+
$FieldValue = $CurrentState
126+
}
127+
Set-CIPPStandardsCompareField -FieldName 'standards.SPFileRequests' -FieldValue $FieldValue -Tenant $Tenant
128+
}
129+
}

0 commit comments

Comments
 (0)