Skip to content

Commit f0d03d0

Browse files
authored
Add -KnowledgeAgentSelectedSitesList parameter to Set-PnPTenant cmdlet (#5091)
1 parent ad42ab5 commit f0d03d0

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

documentation/Set-PnPTenant.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,23 @@ Accept pipeline input: False
25842584
Accept wildcard characters: False
25852585
```
25862586

2587+
### -KnowledgeAgentSelectedSitesList
2588+
2589+
Specifies a list of site collection URLs that should be selected for the tenant Knowledge Agent. Each entry must be a full site URL (for example: "https://contoso.sharepoint.com/sites/team1"). The cmdlet will resolve each URL to the corresponding site id and configure the tenant Knowledge Agent to target those sites.
2590+
2591+
Note: Running `Set-PnPTenant` with `-KnowledgeAgentSelectedSitesList` will overwrite any existing configured Knowledge Agent sites in the tenant with the supplied list. To clear the configured list, pass an empty array: `-KnowledgeAgentSelectedSitesList @()`.
2592+
2593+
```yaml
2594+
Type: String[]
2595+
Parameter Sets: (All)
2596+
2597+
Required: False
2598+
Position: Named
2599+
Default value: None
2600+
Accept pipeline input: False
2601+
Accept wildcard characters: False
2602+
```
2603+
25872604
### -AllowSensitivityLabelOnRecords
25882605
Allows sensitivity label on records.
25892606

src/Commands/Admin/SetTenant.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ public class SetTenant : PnPSharePointOnlineAdminCmdlet
531531
[Parameter(Mandatory = false)]
532532
public bool? DelayDenyAddAndCustomizePagesEnforcementOnClassicPublishingSites { private set; get; }
533533

534+
[Parameter(Mandatory = false)]
535+
public string[] KnowledgeAgentSelectedSitesList { private set; get; }
536+
534537
protected override void ExecuteCmdlet()
535538
{
536539
AdminContext.Load(Tenant);
@@ -1676,6 +1679,53 @@ protected override void ExecuteCmdlet()
16761679
Tenant.KnowledgeAgentEnabled = KnowledgeAgentEnabled.Value;
16771680
modified = true;
16781681
}
1682+
if (KnowledgeAgentSelectedSitesList != null)
1683+
{
1684+
if (KnowledgeAgentSelectedSitesList.Length == 0)
1685+
{
1686+
// Explicit empty array passed - clear configured Knowledge Agent sites
1687+
Tenant.KnowledgeAgentSiteList = [];
1688+
modified = true;
1689+
}
1690+
else
1691+
{
1692+
// Build a GUID array by resolving each provided site URL to its SiteProperties and extracting the Id
1693+
var siteIdList = new List<Guid>();
1694+
var tenantForLookup = new Tenant(AdminContext);
1695+
1696+
foreach (var siteUrl in KnowledgeAgentSelectedSitesList)
1697+
{
1698+
if (string.IsNullOrWhiteSpace(siteUrl))
1699+
{
1700+
continue;
1701+
}
1702+
1703+
try
1704+
{
1705+
// The GetSitePropertiesByUrl call requires the tenant admin context
1706+
var siteProps = tenantForLookup.GetSitePropertiesByUrl(siteUrl, includeDetail: false);
1707+
tenantForLookup.Context.Load(siteProps, sp => sp.SiteId);
1708+
tenantForLookup.Context.ExecuteQueryRetry();
1709+
if (siteProps != null && siteProps.SiteId != Guid.Empty)
1710+
{
1711+
siteIdList.Add(siteProps.SiteId);
1712+
}
1713+
else
1714+
{
1715+
LogWarning($"Unable to resolve site URL '{siteUrl}' to a site id. It will be skipped.");
1716+
}
1717+
}
1718+
catch (Exception ex)
1719+
{
1720+
// Don't fail the whole cmdlet for one bad URL; log warning and continue
1721+
LogWarning($"Error resolving site URL '{siteUrl}': {ex.Message}. It will be skipped.");
1722+
}
1723+
}
1724+
1725+
Tenant.KnowledgeAgentSiteList = siteIdList.ToArray();
1726+
modified = true;
1727+
}
1728+
}
16791729
if (GuestSharingGroupAllowListInTenantByPrincipalIdentity != null)
16801730
{
16811731
if (GuestSharingGroupAllowListInTenantByPrincipalIdentity.Length > 0)

0 commit comments

Comments
 (0)