-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplyTemplate.ps1
More file actions
50 lines (39 loc) · 1.44 KB
/
Copy pathApplyTemplate.ps1
File metadata and controls
50 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, HelpMessage="Enter the URL of the target site, e.g. 'https://intranet.mydomain.com/sites/targetSite'")]
[String]
$TargetSiteUrl,
[Parameter(Mandatory = $true, HelpMessage="Enter the filepath for the template, e.q. Folder\File.xml or Folder\File.pnp")]
[String]
$FilePath,
[Parameter(Mandatory = $false, HelpMessage="Optional administration credentials")]
[PSCredential]
$Credentials
)
if($Credentials -eq $null)
{
$Credentials = Get-Credential -Message "Enter Admin Credentials"
}
Write-Host -ForegroundColor Yellow "Target Site URL: $targetSiteUrl"
Write-Host -ForegroundColor Yellow "Applying Template: $FilePath"
try
{
Connect-PnPOnline $TargetSiteUrl -Credentials $Credentials -ErrorAction Stop
Apply-PnPProvisioningTemplate -Path $FilePath
$favList = Get-PnPList -Identity "Lists/Favourites" -Includes ReadSecurity, WriteSecurity
$favList.ReadSecurity = 2
$favList.WriteSecurity = 2
$authorField = $favList.Fields.GetByInternalNameOrTitle("Author")
$authorField.Indexed = $true
$authorField.Update()
$favList.Update()
$favList.Context.ExecuteQuery()
Disconnect-PnPOnline
}
catch
{
Write-Host -ForegroundColor Red "Exception occurred!"
Write-Host -ForegroundColor Red "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host -ForegroundColor Red "Exception Message: $($_.Exception.Message)"
}