|
1 | | -using Microsoft.Online.SharePoint.TenantManagement; |
| 1 | +using Microsoft.Online.SharePoint.TenantAdministration; |
| 2 | +using Microsoft.Online.SharePoint.TenantManagement; |
2 | 3 | using Microsoft.SharePoint.Client; |
3 | 4 | using PnP.Framework; |
4 | 5 | using PnP.PowerShell.Commands.Base; |
@@ -59,26 +60,64 @@ protected override void ExecuteCmdlet() |
59 | 60 | Uri uri = BaseUri; |
60 | 61 | Url = $"{uri.ToString().TrimEnd('/')}/{Url.TrimStart('/')}"; |
61 | 62 | } |
62 | | - Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction; |
63 | 63 |
|
64 | | - Guid newSiteId = Tenant.CreateSiteCollection(Url, Title, Owner, Template, (int)StorageQuota, |
65 | | - (int)StorageQuotaWarningLevel, TimeZone, (int)ResourceQuota, (int)ResourceQuotaWarningLevel, Lcid, |
66 | | - RemoveDeletedSite, Wait, Wait == true ? timeoutFunction : null); |
67 | | - |
68 | | - if (newSiteId != Guid.Empty && Wait && SharingCapability.HasValue) |
| 64 | + if (ParameterSpecified(nameof(RemoveDeletedSite))) |
69 | 65 | { |
70 | | - var props = Tenant.GetSitePropertiesByUrl(Url, true); |
71 | | - Tenant.Context.Load(props); |
72 | | - Tenant.Context.ExecuteQueryRetry(); |
| 66 | + Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction; |
73 | 67 |
|
74 | | - props.SharingCapability = SharingCapability.Value; |
| 68 | + Guid newSiteId = Tenant.CreateSiteCollection(Url, Title, Owner, Template, (int)StorageQuota, |
| 69 | + (int)StorageQuotaWarningLevel, TimeZone, (int)ResourceQuota, (int)ResourceQuotaWarningLevel, Lcid, |
| 70 | + RemoveDeletedSite, Wait, Wait == true ? timeoutFunction : null); |
75 | 71 |
|
76 | | - var op = props.Update(); |
77 | | - AdminContext.Load(op, i => i.IsComplete, i => i.PollingInterval); |
| 72 | + if (newSiteId != Guid.Empty && Wait && SharingCapability.HasValue) |
| 73 | + { |
| 74 | + SetSharingCapability(Url, SharingCapability.Value); |
| 75 | + } |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + SiteCreationProperties siteCreationProperties = new SiteCreationProperties |
| 80 | + { |
| 81 | + Url = Url, |
| 82 | + Owner = Owner, |
| 83 | + Title = Title, |
| 84 | + Template = Template, |
| 85 | + StorageMaximumLevel = StorageQuota, |
| 86 | + StorageWarningLevel = StorageQuotaWarningLevel, |
| 87 | + TimeZoneId = TimeZone, |
| 88 | + UserCodeMaximumLevel = ResourceQuota, |
| 89 | + UserCodeWarningLevel = ResourceQuotaWarningLevel, |
| 90 | + Lcid = Lcid |
| 91 | + }; |
| 92 | + |
| 93 | + SpoOperation spoOperation = Tenant.CreateSite(siteCreationProperties); |
| 94 | + AdminContext.Load(spoOperation, s => s.IsComplete, s => s.PollingInterval, s => s.HasTimedout); |
78 | 95 | AdminContext.ExecuteQueryRetry(); |
| 96 | + |
| 97 | + if (Wait) |
| 98 | + { |
| 99 | + PollOperation(spoOperation); |
| 100 | + } |
| 101 | + |
| 102 | + if (Wait && SharingCapability.HasValue) |
| 103 | + { |
| 104 | + SetSharingCapability(Url, SharingCapability.Value); |
| 105 | + } |
79 | 106 | } |
80 | 107 | } |
81 | 108 |
|
| 109 | + private void SetSharingCapability(string url, SharingCapabilities sharingCapability) |
| 110 | + { |
| 111 | + var props = Tenant.GetSitePropertiesByUrl(url, true); |
| 112 | + Tenant.Context.Load(props); |
| 113 | + Tenant.Context.ExecuteQueryRetry(); |
| 114 | + |
| 115 | + props.SharingCapability = sharingCapability; |
| 116 | + var op = props.Update(); |
| 117 | + AdminContext.Load(op, i => i.IsComplete, i => i.PollingInterval); |
| 118 | + AdminContext.ExecuteQueryRetry(); |
| 119 | + } |
| 120 | + |
82 | 121 | private bool TimeoutFunction(TenantOperationMessage message) |
83 | 122 | { |
84 | 123 | if (message == TenantOperationMessage.CreatingSiteCollection) |
|
0 commit comments