Skip to content

Commit 6456474

Browse files
Merge pull request #1575 from Zacgoose/spo-file-requests
Add Invoke-CIPPStandardSPFileRequests function
2 parents 56225b8 + 8f1801e commit 6456474

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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-LogMessage -API 'Standards' -tenant $tenant -message 'The tenant is not licenced for this standard SPFileRequests' -sev Error
38+
return $true
39+
}
40+
41+
try {
42+
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object _ObjectIdentity_, TenantFilter, CoreRequestFilesLinkEnabled, OneDriveRequestFilesLinkEnabled, CoreRequestFilesLinkExpirationInDays, OneDriveRequestFilesLinkExpirationInDays
43+
}
44+
catch {
45+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to get current state of SPO tenant details' -sev Error
46+
return
47+
}
48+
49+
# Input validation
50+
if (($Settings.state -eq $null) -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
51+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Invalid state parameter set for standard SPFileRequests' -sev Error
52+
return
53+
}
54+
55+
$WantedState = $Settings.state
56+
$ExpirationDays = $Settings.expirationDays
57+
$HumanReadableState = if ($WantedState -eq $true) { 'enabled' } else { 'disabled' }
58+
59+
# Check if current state matches desired state
60+
$CoreStateIsCorrect = if ($CurrentState.CoreRequestFilesLinkEnabled -eq $WantedState) { $true } else { $false }
61+
$OneDriveStateIsCorrect = if ($CurrentState.OneDriveRequestFilesLinkEnabled -eq $WantedState) { $true } else { $false }
62+
$StateIsCorrect = $CoreStateIsCorrect -and $OneDriveStateIsCorrect
63+
64+
# Check expiration settings if specified
65+
$ExpirationIsCorrect = $true
66+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
67+
$CoreExpirationIsCorrect = ($CurrentState.CoreRequestFilesLinkExpirationInDays -eq $ExpirationDays)
68+
$OneDriveExpirationIsCorrect = ($CurrentState.OneDriveRequestFilesLinkExpirationInDays -eq $ExpirationDays)
69+
$ExpirationIsCorrect = $CoreExpirationIsCorrect -and $OneDriveExpirationIsCorrect
70+
}
71+
72+
$AllSettingsCorrect = $StateIsCorrect -and $ExpirationIsCorrect
73+
74+
if ($Settings.remediate -eq $true) {
75+
76+
if ($AllSettingsCorrect -eq $false) {
77+
try {
78+
$Properties = @{
79+
CoreRequestFilesLinkEnabled = $WantedState
80+
OneDriveRequestFilesLinkEnabled = $WantedState
81+
}
82+
83+
# Add expiration settings if specified and feature is being enabled
84+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
85+
$Properties['CoreRequestFilesLinkExpirationInDays'] = $ExpirationDays
86+
$Properties['OneDriveRequestFilesLinkExpirationInDays'] = $ExpirationDays
87+
}
88+
89+
$CurrentState | Set-CIPPSPOTenant -Properties $Properties
90+
91+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
92+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set File Requests to $HumanReadableState$ExpirationMessage" -sev Info
93+
} catch {
94+
$ErrorMessage = Get-CippException -Exception $_
95+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set File Requests to $HumanReadableState. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
96+
}
97+
} else {
98+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
99+
Write-LogMessage -API 'Standards' -tenant $tenant -message "File Requests are already set to the wanted state of $HumanReadableState$ExpirationMessage" -sev Info
100+
}
101+
}
102+
103+
if ($Settings.alert -eq $true) {
104+
if ($AllSettingsCorrect -eq $true) {
105+
$ExpirationMessage = if ($ExpirationDays -ne $null -and $WantedState -eq $true) { " with $ExpirationDays day expiration" } else { "" }
106+
Write-LogMessage -API 'Standards' -tenant $tenant -message "File Requests are already set to the wanted state of $HumanReadableState$ExpirationMessage" -sev Info
107+
} else {
108+
$AlertMessage = "File Requests are not set to the wanted state of $HumanReadableState"
109+
if ($ExpirationDays -ne $null -and $WantedState -eq $true) {
110+
$AlertMessage += " with $ExpirationDays day expiration"
111+
}
112+
Write-StandardsAlert -message $AlertMessage -object $CurrentState -tenant $tenant -standardName 'SPFileRequests' -standardId $Settings.standardId
113+
Write-LogMessage -API 'Standards' -tenant $tenant -message $AlertMessage -sev Info
114+
}
115+
}
116+
117+
if ($Settings.report -eq $true) {
118+
Add-CIPPBPAField -FieldName 'SPFileRequestsEnabled' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
119+
Add-CIPPBPAField -FieldName 'SPCoreFileRequestsEnabled' -FieldValue $CurrentState.CoreRequestFilesLinkEnabled -StoreAs bool -Tenant $Tenant
120+
Add-CIPPBPAField -FieldName 'SPOneDriveFileRequestsEnabled' -FieldValue $CurrentState.OneDriveRequestFilesLinkEnabled -StoreAs bool -Tenant $Tenant
121+
122+
if ($ExpirationDays -ne $null) {
123+
Add-CIPPBPAField -FieldName 'SPCoreFileRequestsExpirationDays' -FieldValue $CurrentState.CoreRequestFilesLinkExpirationInDays -StoreAs string -Tenant $Tenant
124+
Add-CIPPBPAField -FieldName 'SPOneDriveFileRequestsExpirationDays' -FieldValue $CurrentState.OneDriveRequestFilesLinkExpirationInDays -StoreAs string -Tenant $Tenant
125+
}
126+
127+
if ($AllSettingsCorrect) {
128+
$FieldValue = $true
129+
} else {
130+
$FieldValue = $CurrentState
131+
}
132+
Set-CIPPStandardsCompareField -FieldName 'standards.SPFileRequests' -FieldValue $FieldValue -Tenant $Tenant
133+
}
134+
}

0 commit comments

Comments
 (0)