Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add csv file sample to the docs for Remove-PnPTenantRestrictedSearchAllowedList and Add-PnPTenantRestrictedSearchAllowedList #4413

Closed
wants to merge 7 commits into from
16 changes: 16 additions & 0 deletions documentation/Add-PnPTenantRestrictedSearchAllowedList.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,33 @@ Add-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv

Adds site URLs to the allowed list from a CSV file. The first line, which is assumed to be a header, is skipped.

Sample CSV file content:

```csv
SiteUrl
https://contoso.sharepoint.com/sites/Company311
https://contoso.sharepoint.com/sites/contosoportal
```

### EXAMPLE 2
```powershell
Add-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv"
```

Adds site URLs to the allowed list from a CSV file.

Sample CSV file content:

```csv
https://contoso.sharepoint.com/sites/Company311
https://contoso.sharepoint.com/sites/contosoportal
```

### 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
Expand Down
124 changes: 124 additions & 0 deletions documentation/Remove-PnPTenantRestrictedSearchAllowedList.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPTenantRestrictedSearchAllowedList.html
external help file: PnP.PowerShell.dll-Help.xml
title: Remove-PnPTenantRestrictedSearchAllowedList
---

# Remove-PnPTenantRestrictedSearchAllowedList

## SYNOPSIS
Removes site URLs from 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
Remove-PnPTenantRestrictedSearchAllowedList [-SitesListFileUrl <String>] [-SitesList <String[]>] [-ContainsHeaders <SwitchParameter>] [-Connection <PnPConnection>]
```

## DESCRIPTION

Removes site URLs from 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
Remove-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv" -ContainsHeader
```

Removes site URLs from the allowed list from a CSV file. The first line, which is assumed to be a header, is skipped.

Sample CSV file content:

```csv
SiteUrl
https://contoso.sharepoint.com/sites/Company311
https://contoso.sharepoint.com/sites/contosoportal
```

### EXAMPLE 2
```powershell
Remove-PnPTenantRestrictedSearchAllowedList -SitesListFileUrl "C:\temp\sitelist.csv"
```

Removes site URLs from the allowed list from a CSV file.

Sample CSV file content:

```csv
https://contoso.sharepoint.com/sites/Company311
https://contoso.sharepoint.com/sites/contosoportal
```

### EXAMPLE 3
```powershell
Remove-PnPTenantRestrictedSearchAllowedList -SitesList @("https://contoso.sharepoint.com/sites/Company311","https://contoso.sharepoint.com/sites/contosoportal")
```
Removes the specified sites from 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 removed from 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 remove from 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 src/Commands/Admin/RemoveTenantRestrictedSearchAllowedList.cs
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.Remove, "PnPTenantRestrictedSearchAllowedList", DefaultParameterSetName = ParameterSet_SiteList)]
public class RemoveTenantRestrictedSearchAllowedList : 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.RemoveSPORestrictedSearchAllowedList(_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();
}
}
}