Skip to content

Commit 0dd3f95

Browse files
Added Remove-PnPSearchExternalItem (#4378)
* Implemented new cmdlet * Added PR reference --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent d3a64a9 commit 0dd3f95

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2121
- 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)
2222
- 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)
2323
- 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)
24+
- Added `Remove-PnPSearchExternalItem` which allows for removal of an external item from the Microsoft Search index [#4378](https://github.com/pnp/powershell/pull/4378)
2425
- Added `-Scopes` parameter to `Get-PnPAccessToken` cmdlet to retrieve access token with specific scopes.
2526

2627
### Changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
schema: 2.0.0
4+
applicable: SharePoint Online
5+
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPSearchExternalItem.html
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
title: Remove-PnPSearchExternalItem
8+
---
9+
10+
# Remove-PnPSearchExternalItem
11+
12+
## SYNOPSIS
13+
14+
**Required Permissions**
15+
16+
* Microsoft Graph API : One of ExternalItem.ReadWrite.OwnedBy, ExternalItem.ReadWrite.All as a delegate or application permission
17+
18+
Removes an external item from an external connector in Microsoft Search
19+
20+
## SYNTAX
21+
22+
```powershell
23+
Remove-PnPSearchExternalItem -ItemId <String> -ConnectionId <SearchExternalConnectionPipeBind> [-Verbose] [-Connection <PnPConnection>]
24+
```
25+
26+
## DESCRIPTION
27+
28+
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.
29+
30+
## EXAMPLES
31+
32+
### EXAMPLE 1
33+
```powershell
34+
Remove-PnPSearchExternalItem -ConnectionId "pnppowershell" -ItemId "12345"
35+
```
36+
37+
This will remove the external item with the identifier "12345" from the external Microsoft Search index connector named "pnppowershell".
38+
39+
## PARAMETERS
40+
41+
### -Connection
42+
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.
43+
44+
```yaml
45+
Type: PnPConnection
46+
Parameter Sets: (All)
47+
Required: False
48+
Position: Named
49+
Default value: None
50+
Accept pipeline input: False
51+
Accept wildcard characters: False
52+
```
53+
54+
### -ItemId
55+
Unique identifier of the external item in Microsoft Search that you wish to remove.
56+
57+
```yaml
58+
Type: String
59+
Parameter Sets: (All)
60+
Required: True
61+
Position: Named
62+
Default value: None
63+
Accept pipeline input: False
64+
Accept wildcard characters: False
65+
```
66+
67+
### -ConnectionId
68+
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.
69+
70+
```yaml
71+
Type: SearchExternalConnectionPipeBind
72+
Parameter Sets: (All)
73+
Required: True
74+
Default value: None
75+
Accept pipeline input: True
76+
Accept wildcard characters: False
77+
```
78+
79+
### -Verbose
80+
When provided, additional debug statements will be shown while executing the cmdlet.
81+
82+
```yaml
83+
Type: SwitchParameter
84+
Parameter Sets: (All)
85+
86+
Required: False
87+
Position: Named
88+
Default value: None
89+
Accept pipeline input: False
90+
Accept wildcard characters: False
91+
```
92+
93+
## RELATED LINKS
94+
95+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
96+
[Microsoft Graph documentation](https://learn.microsoft.com/graph/api/externalconnectors-externalitem-delete)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Management.Automation;
2+
using PnP.PowerShell.Commands.Base;
3+
using PnP.PowerShell.Commands.Base.PipeBinds;
4+
using PnP.PowerShell.Commands.Attributes;
5+
using PnP.PowerShell.Commands.Utilities.REST;
6+
using System.Management.Automation.Remoting;
7+
8+
namespace PnP.PowerShell.Commands.Search
9+
{
10+
[Cmdlet(VerbsCommon.Remove, "PnPSearchExternalItem")]
11+
[RequiredApiDelegatedOrApplicationPermissions("graph/ExternalItem.ReadWrite.OwnedBy")]
12+
[RequiredApiDelegatedOrApplicationPermissions("graph/ExternalItem.ReadWrite.All")]
13+
[OutputType(typeof(Model.Graph.MicrosoftSearch.ExternalItem))]
14+
public class RemoveSearchExternalItem : PnPGraphCmdlet
15+
{
16+
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
17+
public SearchExternalConnectionPipeBind ConnectionId;
18+
19+
[Parameter(Mandatory = true)]
20+
public string ItemId;
21+
22+
protected override void ExecuteCmdlet()
23+
{
24+
var connection = ConnectionId.GetExternalConnection(this, Connection, AccessToken);
25+
26+
try
27+
{
28+
var response = GraphHelper.Delete(this, Connection, $"beta/external/connections/{connection.Id}/items/{ItemId}", AccessToken);
29+
WriteVerbose($"External item with ID '{ItemId}' successfully removed from external connection '{connection.Id}'");
30+
}
31+
catch (PSInvalidOperationException ex)
32+
{
33+
throw new PSInvalidOperationException($"Removing external item with ID '{ItemId}' from external connection '{connection.Id}' failed with message '{ex.Message}'", ex);
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)