-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3993 from reshmee011/rssaddsites
new cmdlet for Add-PnPTenantRestrictedSearchAllowedList
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
documentation/Add-PnPTenantRestrictedSearchAllowedList.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Add-PnPTenantRestrictedSearchAllowedList.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Add-PnPTenantRestrictedSearchAllowedList | ||
--- | ||
|
||
# Add-PnPTenantRestrictedSearchAllowedList | ||
|
||
## SYNOPSIS | ||
Adds site URLs to the allowed list when Restricted SharePoint Search is enabled. The URLs can be provided as a string array or read from a CSV file. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Add-PnPTenantRestrictedSearchAllowedList [-SitesListFileUrl <String>] [-SitesList <String[]>] [-ContainsHeaders <SwitchParameter>] [-Connection <PnPConnection>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Adds site URLs to the allowed list when Restricted SharePoint Search is enabled. The URLs can be provided directly as a string array or read from a CSV file. At present, a maximum of 100 sites can be added to the allowed list. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Add-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv" -ContainsHeader | ||
``` | ||
|
||
Adds site URLs to the allowed list from a CSV file. The first line, which is assumed to be a header, is skipped. | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
Add-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv" | ||
``` | ||
|
||
Adds site URLs to the allowed list from a CSV file. | ||
|
||
### EXAMPLE 3 | ||
```powershell | ||
Add-PnPTenantRestrictedSearchAllowedList -SitesList @("https://contoso.sharepoint.com/sites/Company311","https://contoso.sharepoint.com/sites/contosoportal") | ||
``` | ||
Adds the specified sites to the allowed list. | ||
|
||
## PARAMETERS | ||
|
||
### -Connection | ||
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -SitesListFileUrl | ||
Specifies the path of the CSV file that contains a list of site URLs to be added to the allowed list when the tenant is set to Restricted Tenant Search Mode. | ||
```yaml | ||
Type: String | ||
Parameter Sets: File | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -SitesList | ||
Specifies a collection of sites to add to the allowed list. | ||
```yaml | ||
Type: String[] | ||
Parameter Sets: SiteList | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Containsheader | ||
If specified, this switch skips the first line from the CSV file, which is assumed to be a header. | ||
```yaml | ||
Type: SwitchParamter | ||
Parameter Sets: File | ||
|
||
Required: False | ||
Position: Named | ||
Default value: False | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[How does Restricted SharePoint Search work?](https://learn.microsoft.com/sharepoint/restricted-sharepoint-search) | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
75 changes: 75 additions & 0 deletions
75
src/Commands/Admin/AddTenantRestrictedSearchAllowedList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Microsoft.Online.SharePoint.TenantAdministration; | ||
using Microsoft.SharePoint.Client; | ||
using PnP.PowerShell.Commands.Base; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Linq; | ||
using System; | ||
|
||
namespace PnP.PowerShell.Commands.Admin | ||
{ | ||
[Cmdlet(VerbsCommon.Add, "PnPTenantRestrictedSearchAllowedList", DefaultParameterSetName = ParameterSet_SiteList)] | ||
public class AddTenantRestrictedSearchAllowedList : PnPAdminCmdlet | ||
{ | ||
private const string ParameterSet_SiteList = "SiteList"; | ||
private const string ParameterSet_File = "File"; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_SiteList)] | ||
public string[] SitesList; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_File)] | ||
public string SitesListFileUrl; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_File)] | ||
public SwitchParameter ContainsHeader; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
IList<string> _sitelist = null; | ||
if (ParameterSetName == ParameterSet_File) | ||
{ | ||
_sitelist = ReadFileContents(); | ||
} | ||
else if (ParameterSetName == ParameterSet_SiteList) | ||
{ | ||
_sitelist = SitesList; | ||
} | ||
else | ||
{ | ||
throw new ArgumentException("Parameter set cannot be resolved using the specified named parameters."); | ||
} | ||
|
||
if (_sitelist == null) | ||
{ | ||
throw new InvalidOperationException("SiteList cannot be null"); | ||
} | ||
|
||
if(_sitelist.Count > 100) | ||
{ | ||
WriteWarning($"The maximum number of sites that can be added to the allowed list is 100. You have specified {_sitelist.Count} sites. Will try to add them anyway."); | ||
} | ||
|
||
Tenant.AddSPORestrictedSearchAllowedList(_sitelist); | ||
AdminContext.ExecuteQueryRetry(); | ||
} | ||
|
||
private IList<string> ReadFileContents() | ||
{ | ||
var lines = System.IO.File.ReadAllLines(SitesListFileUrl); | ||
if (ContainsHeader) | ||
{ | ||
lines = lines.Skip(1).ToArray(); | ||
} | ||
|
||
foreach (var line in lines) | ||
{ | ||
if (line.Contains(',')) | ||
{ | ||
throw new InvalidOperationException("File should only contain one column and no commas"); | ||
} | ||
} | ||
|
||
return lines.ToList(); | ||
} | ||
} | ||
} |