Skip to content

Commit

Permalink
Implemented new cmdlet
Browse files Browse the repository at this point in the history
  • Loading branch information
KoenZomers committed Oct 4, 2024
1 parent df7b5e3 commit cf78c71
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-X509KeyStorageFlags` parameter to `Connect-PnPOnline` cmdlet which allows setting of how private keys are to be imported. [#4324](https://github.com/pnp/powershell/pull/4324)
- Added `-RestrictContentOrgWideSearch` parameter to `Set-PnPSite` which allows for applying the Restricted Content Discoverability (RCD) setting to a site [#4335](https://github.com/pnp/powershell/pull/4335)
- Added `-LaunchBrowser` parameter to `Register-PnPEntraIDAppForInteractiveLogin` and `Register-PnPEntraIDApp` cmdlets to open browser and continue app registration in the browser. [#4347](https://github.com/pnp/powershell/pull/4347) & [#4348](https://github.com/pnp/powershell/pull/4348)
- Added `Remove-PnPSearchExternalItem` which allows for removal of an external item from the Microsoft Search index

### Changed

Expand Down
96 changes: 96 additions & 0 deletions documentation/Remove-PnPSearchExternalItem.md
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)
37 changes: 37 additions & 0 deletions src/Commands/Search/RemoveSearchExternalItem.cs
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);
}
}
}
}

0 comments on commit cf78c71

Please sign in to comment.