You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Calling the PnP provisioning engine from a site script
9
9
10
+
> [!NOTE]
11
+
> This article uses a version of PnP PowerShell that is currently in pre-release and planned to GA in January 2021. As Azure Functions run PowerShell Core, you will have to use this version of PnP PowerShell in your Azure function. For more information about this version of PnP PowerShell see https://pnp.github.io/powershell.
12
+
10
13
Site designs offer a great way to standardize the look and feel of your site collections. However, you can't do some things with site designs, like add a footer to every page. You can use the PnP provisioning engine to create a template that you can use to provision an Application Customizer to a site. This Application Customizer can then update your page design, for example to register a footer on every page.
11
14
12
15
This article describes how to create a site design that applies a PnP provisioning template to a site. The template will add an Application Customizer to render a footer.
@@ -18,51 +21,31 @@ The steps in this article use the following components:
18
21
- Azure Queue storage
19
22
- Azure Functions
20
23
- A SharePoint Framework (SPFx) solution
21
-
- A PnP provisioning template
24
+
- A PnP site template
22
25
- A PnP PowerShell script
23
-
- An app ID and app secret with administrative rights on your tenant
26
+
- An Azure AD App Registration
24
27
25
-
You'll use these components to trigger the PnP provisioning code after you create the site and apply the site design.
28
+
You will use these components to trigger the PnP provisioning code after you create the site and apply the site design.
To set up app-only access, you need to have two different pages on your tenant—one on the regular site, and the other on your SharePoint administration site.
32
-
33
-
1. Go to following URL in your tenant: `https://[yourtenant].sharepoint.com/_layouts/15/appregnew.aspx` (you can go to any site, but for now pick the root site).
34
-
35
-
2. Next to the **Client Id** and **Client Secret** fields, choose the **Generate** button.
36
-
37
-
3. Enter a title for your app, such as **Site Provisioning**.
38
-
39
-
4. In the **App Domain** box, enter **localhost**.
34
+
We are going to use authentication with a clientid and a certificate in this tutorial.
40
35
41
-
5. In the **Redirect URI** box, enter **https://localhost**.
42
-
43
-

44
-
45
-
6. Choose **Create**.
36
+
1. Create a new self-signed certificate with PnP PowerShell on your computer:
Replace **contoso.onmicrosoft.com** with your tenant.
46
42
47
-
7. Copy the values for **Client Id** and **Client Secret** because you will need them later.
43
+
Follow the steps carefully.
48
44
45
+
As a result of the command a new Azure AD Application will be registered, permissions will be set correctly, and you will have provided consent to use this application in your tenant. Notice that you require write access to the Azure AD for this.
46
+
1. Copy the values the cmdlet returns as you will need the pfx file and the AzureAppId value later.
49
47
<br/>
50
48
51
-
Next, trust the app, so that it has the appropriate access to your tenant:
52
-
53
-
1. Go to `https://[yourtenant]-admin.sharepoint.com/_layouts/appinv.aspx` (notice the `-admin` in the URL).
54
-
1. In the **App Id** field, paste the **Client ID** that you copied, and choose **Lookup**.
55
-
1. In the **Permission Request XML** field, paste the following XML:
1. To confirm that you want to trust this app, choose **Trust It**.
65
-
66
49
67
50
## Create the Azure Queue storage
68
51
@@ -171,116 +154,78 @@ Copy the following provisioning template XML to a new file and save the file as
171
154
172
155
1. Go to the [Azure Portal](https://portal.azure.com).
173
156
1. Choose **+ Create a resource**.
174
-
1. Search for **Function App** and create a new function app. In the **Storage** field, select **Use existing**, and select the storage account that you created earlier. Set the other values as required.
175
-
1. Within the Function App select **Configuration** > **Function runtime settings** and change the runtime version from **~3** to **~1**.
176
-
177
-

178
-
179
-
> [!NOTE]
180
-
> Function Apps based on the runtime version ~3 or ~2 only support PowerShell Core as programming language. At this moment, PnP PowerShell cmdlets can be only executed under PowerShell (and not on PowerShell Core).
181
-
>
182
-
> First, to make available Powershell at the level of the Function App, the runtime version has to be set to **~1**.
183
-
>
184
-
> Secondly, PowerShell can be only activated from the **classic experience** of the Azure Portal, by enabling the **Experimental Language Support**, at the level of the Function App.
185
-
>
186
-
> Read more about [Azure Functions runtime versions.](https://www.microsoft.com/download/details.aspx?id=35588)
187
-
188
-
1. Temporarly switch the Azure Function App's user interface to the **classic experience** from the current experience. Select **Overview** in the left-hand navigation and select **Switch to Classic experience** as shown in the following figure.
189
-
190
-

157
+
1. Search for **Function App** and create a new function app. In the **Storage** field, select **Use existing**, and select the storage account that you created earlier. Set the other values as required, but make sure to select **PowerShell Core** as the **Runtime** and select **7.0** as the **Version**
158
+
159
+

160
+
1. When created, navigate to your new Function App
161
+
1. Select **App Files**
162
+
163
+

164
+
1. In the dropdown menu, select **requirements.psd1** and add a new entry as follows
165
+
```powershell
166
+
# This file enables modules to be automatically managed by the Functions service.
167
+
# See https://aka.ms/functionsmanageddependency for additional information.
168
+
#
169
+
@{
170
+
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
171
+
'Az' = '5.*'
172
+
# For the latest supported version, go to 'https://www.powershellgallery.com/packages/PnP.PowerShell'.
173
+
'PnP.PowerShell' = '0.2.17-nightly'
174
+
}
175
+
```
176
+
Save the file. Notice, that if you do no intent to use the Azure PowerShell Cmdlets you can remove that entry from this file. The requirements.psd1 file makes sure that specific PowerShell modules will be available to all functions. At the first execution of the Azure Function these modules will be downloaded and made available. You can also use wildcard references for the version. See for more information about this file here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#dependency-management
191
177
192
-
1. Create a new Azure Function **Functions** > **New function**:
178
+
1. Create a new Azure Function **Functions** > **Add**:
193
179
194
180

195
181
196
-
1. Enable **Experimental Language Support**:
197
-
198
-

199
-
200
-
1. Create a new Queue Triggered function based upon PowerShell:
182
+
1. Create a new Azure Store Queue Trigger function:
201
183
202
184

203
185
204
-
1. Name the function **ApplyPnPProvisioningTemplate**.
186
+
1. Name the function **InvokePnPSiteTemplate**.
205
187
1. Enter the name of the queue you created earlier.
206
-
1. Choose **Create**. An editor where you can enter PowerShell cmdlets will open.
207
-
208
-
Next, you'll upload the PnP PowerShell module so that you can use it in the Azure Function.
188
+
1. Choose **Add**. A new page opens where you can modify the function.
209
189
210
190
> [!NOTE]
211
191
> The Storage account must be in the same region as of Azure Function App, because the resources that talk to one another should be co-located in the same region. This is a requirement for Azure Functions.
212
192
213
-
## Upload the PnP PowerShell module for your Azure Function
214
-
215
-
You'll need to download the PnP PowerShell module so that you can upload it for your Azure Function.
Notice that you're using two environment variables: ```SPO_AppId```and ```SPO_AppSecret```. To set those variables, go to the main Function App page in the Azure Portal (the one with the yellow light bolt icon), select **Configuration** and add two new application settings:
266
-
267
-
1. ```SPO_AppId``` - Set the value to the Client ID you copied in the first step when you created your app on your tenant.
268
-
2. ```SPO_AppSecret``` - Set the value to the Client Secret that you copied in the first step when you created your app on your tenant.
215
+
Replace **[insertyourAppIdHere]** with the value that the `Register-PnPAzureApp` cmdlet returned for AzureAppId.
269
216
270
217
## Create the site design
271
218
272
-
Open PowerShell and make sure that you have the [SharePoint Online Management Shell](https://www.microsoft.com/download/details.aspx?id=35588) installed.
273
-
274
-
Connect to your tenant using **Connect-SPOService**.
219
+
Open PowerShell and connect to your tenant using **Connect-PnPOnline**.
Add-PnPSiteScript -Title "Apply PnP Site Template" -Content $script
262
+
Get-PnPSiteScript
318
263
```
319
264
320
265
1. You will see a list of one or more site scripts, including the site script you just created. Select the ID of the site script that you created and copy it to the clipboard.
321
266
1. Use the following command to create the site design:
322
267
323
268
```powershell
324
-
Add-SPOSiteDesign -Title "Site with footer" -SiteScripts [Paste the ID of the Site Script here] -WebTemplate "64"
269
+
Add-PnPSiteDesign -Title "Site with footer" -SiteScriptIds [Paste the ID of the Site Script here] -WebTemplate TeamSite
325
270
```
326
271
327
-
The **Add-SPOSiteDesign** cmdlet associates the site design with the team site. If you want to associate the design with a communication site, use the value "68".
328
-
329
272
## Verify the results
330
273
331
274
After you created your Azure Queue storage, you created the app ID for app-only access, the Azure Function, and the site design. You then triggered the Power Automate flow from the site design.
0 commit comments