Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit d612653

Browse files
Merge pull request #370 from wobba/SetSiteCollectionAdmins
Added support to set site collection administrators as per issue #232
2 parents f33299a + 35d476c commit d612653

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Commands/Admin/SetTenantSite.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
#if !ONPREMISES
2+
using System;
23
using System.Management.Automation;
34
using Microsoft.Online.SharePoint.TenantManagement;
45
using Microsoft.SharePoint.Client;
56
using SharePointPnP.PowerShell.CmdletHelpAttributes;
67
using SharePointPnP.PowerShell.Commands.Base;
8+
using System.Collections.Generic;
9+
using OfficeDevPnP.Core.Entities;
710

811
namespace SharePointPnP.PowerShell.Commands
912
{
1013
[Cmdlet(VerbsCommon.Set, "SPOTenantSite")]
11-
[CmdletHelp(@"Office365 only: Uses the tenant API to set site information.",
14+
[CmdletHelp(@"Office365 only: Uses the tenant API to set site information.",
1215
Category = CmdletHelpCategory.TenantAdmin)]
1316
[CmdletExample(
1417
Code = @"PS:> Set-SPOTenantSite -Url https://contoso.sharepoint.com -Title 'Contoso Website' -Sharing Disabled",
1518
Remarks = @"This will set the title of the site collection with the URL 'https://contoso.sharepoint.com' to 'Contoso Website' and disable sharing on this site collection.", SortOrder = 1)]
1619
[CmdletExample(
1720
Code = @"PS:> Set-SPOTenantSite -Url https://contoso.sharepoint.com -Title 'Contoso Website' -StorageWarningLevel 8000 -StorageMaximumLevel 10000",
1821
Remarks = @"This will set the title of the site collection with the URL 'https://contoso.sharepoint.com' to 'Contoso Website', set the storage warning level to 8GB and set the storage maximum level to 10GB.", SortOrder = 2)]
22+
[CmdletExample(
23+
Code = @"PS:> Set-SPOTenantSite -Url https://contoso.sharepoint.com/sites/sales -Owners 'i:0#.f|membership|[email protected]'",
24+
Remarks = @"This will set [email protected] as a site collection owner at 'https://contoso.sharepoint.com/sites/sales'.", SortOrder = 3)]
1925
public class SetTenantSite : SPOAdminCmdlet
2026
{
21-
[Parameter(Mandatory = false, HelpMessage = "Specifies the URL of the site", Position=0, ValueFromPipeline=true)]
27+
[Parameter(Mandatory = false, HelpMessage = "Specifies the URL of the site", Position = 0, ValueFromPipeline = true)]
2228
public string Url;
2329

2430
[Parameter(Mandatory = false, HelpMessage = "Specifies the title of the site")]
@@ -42,11 +48,24 @@ public class SetTenantSite : SPOAdminCmdlet
4248
[Parameter(Mandatory = false, HelpMessage = "Specifies if the site administrator can upgrade the site collection")]
4349
public SwitchParameter? AllowSelfServiceUpgrade = null;
4450

51+
[Parameter(Mandatory = false, HelpMessage = "Specifies owners to add as site collection adminstrators. Can be both users and groups.")]
52+
public List<string> Owners;
53+
4554
protected override void ExecuteCmdlet()
4655
{
47-
Tenant.SetSiteProperties(Url, title:Title, sharingCapability: Sharing, storageMaximumLevel: StorageMaximumLevel, allowSelfServiceUpgrade: AllowSelfServiceUpgrade, userCodeMaximumLevel: UserCodeMaximumLevel, userCodeWarningLevel: UserCodeWarningLevel);
56+
Tenant.SetSiteProperties(Url, title: Title, sharingCapability: Sharing, storageMaximumLevel: StorageMaximumLevel, allowSelfServiceUpgrade: AllowSelfServiceUpgrade, userCodeMaximumLevel: UserCodeMaximumLevel, userCodeWarningLevel: UserCodeWarningLevel);
57+
58+
if (Owners != null && Owners.Count > 0)
59+
{
60+
var admins = new List<UserEntity>();
61+
foreach (string owner in Owners)
62+
{
63+
var userEntity = new UserEntity { LoginName = owner };
64+
admins.Add(userEntity);
65+
}
66+
Tenant.AddAdministrators(admins, new Uri(Url));
67+
}
4868
}
4969
}
50-
5170
}
5271
#endif

0 commit comments

Comments
 (0)