-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFieldinDocLibrary.ps1
More file actions
34 lines (28 loc) · 1.3 KB
/
AddFieldinDocLibrary.ps1
File metadata and controls
34 lines (28 loc) · 1.3 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
#######################################
#
# Add fields to doc libraries
# 12.16.21 // Matt Peterson
#
######################################
# Connect to SharePoint
# Documentation link: https://pnp.github.io/powershell/cmdlets/Connect-PnPOnline.html
Connect-PnPOnline "https://yourtenant.sharepoint.com" -UseWebLogin
# Get All hubbed sites
# Documentation link: https://pnp.github.io/powershell/cmdlets/Get-PnPHubSiteChild.html
$Sites = Get-PnPHubSiteChild -Identity "https://yourtenant.sharepoint.com/sites/hubsite"
# Loop through the hubbed sites
Foreach ($Site in $Sites){
#Get the hubbed site URL
$childURL = $Site.Url
#Connect to that specific site
Connect-PnPOnline $childURL -UseWebLogin
# Get only document library lists
# Documentation: https://pnp.github.io/powershell/cmdlets/Get-PnPList.html
$Lists = Get-PnPList | Where-Object {$_.BaseTemplate -eq 101 -and $_.Hidden -eq $false}
# Loop through each document library in the specific site
Foreach ($List in $Lists){
Add-PnPField -List $List -Field "FieldName" -Type Text
# For list of field types go to: https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.fieldtype?view=sharepoint-csom
# Using Command: https://pnp.github.io/powershell/cmdlets/Add-PnPField.html
}
}