-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df7b5e3
commit cf78c71
Showing
3 changed files
with
134 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
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,96 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPSearchExternalItem.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Remove-PnPSearchExternalItem | ||
--- | ||
|
||
# Remove-PnPSearchExternalItem | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API : One of ExternalItem.ReadWrite.OwnedBy, ExternalItem.ReadWrite.All as a delegate or application permission | ||
|
||
Removes an external item from an external connector in Microsoft Search | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Remove-PnPSearchExternalItem -ItemId <String> -ConnectionId <SearchExternalConnectionPipeBind> [-Verbose] [-Connection <PnPConnection>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
This cmdlet can be used to remove a specific external item from a Microsoft Search custom connector. The item will be removed from the index and will no longer be available for search results. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Remove-PnPSearchExternalItem -ConnectionId "pnppowershell" -ItemId "12345" | ||
``` | ||
|
||
This will remove the external item with the identifier "12345" from the external Microsoft Search index connector named "pnppowershell". | ||
|
||
## 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 | ||
``` | ||
### -ItemId | ||
Unique identifier of the external item in Microsoft Search that you wish to remove. | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -ConnectionId | ||
The Connection ID or connection instance of the custom connector to use. This is the ID that was entered when registering the custom connector and will indicate for which custom connector this external item is being removed from the Microsoft Search index. | ||
```yaml | ||
Type: SearchExternalConnectionPipeBind | ||
Parameter Sets: (All) | ||
Required: True | ||
Default value: None | ||
Accept pipeline input: True | ||
Accept wildcard characters: False | ||
``` | ||
### -Verbose | ||
When provided, additional debug statements will be shown while executing the cmdlet. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
[Microsoft Graph documentation](https://learn.microsoft.com/graph/api/externalconnectors-externalitem-delete) |
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,37 @@ | ||
using System.Management.Automation; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System.Management.Automation.Remoting; | ||
|
||
namespace PnP.PowerShell.Commands.Search | ||
{ | ||
[Cmdlet(VerbsCommon.Remove, "PnPSearchExternalItem")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/ExternalItem.ReadWrite.OwnedBy")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/ExternalItem.ReadWrite.All")] | ||
[OutputType(typeof(Model.Graph.MicrosoftSearch.ExternalItem))] | ||
public class RemoveSearchExternalItem : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)] | ||
public SearchExternalConnectionPipeBind ConnectionId; | ||
|
||
[Parameter(Mandatory = true)] | ||
public string ItemId; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var connection = ConnectionId.GetExternalConnection(this, Connection, AccessToken); | ||
|
||
try | ||
{ | ||
var response = GraphHelper.Delete(this, Connection, $"beta/external/connections/{connection.Id}/items/{ItemId}", AccessToken); | ||
WriteVerbose($"External item with ID '{ItemId}' successfully removed from external connection '{connection.Id}'"); | ||
} | ||
catch (PSInvalidOperationException ex) | ||
{ | ||
throw new PSInvalidOperationException($"Removing external item with ID '{ItemId}' from external connection '{connection.Id}' failed with message '{ex.Message}'", ex); | ||
} | ||
} | ||
} | ||
} |