SharePoint Online:使用 PowerShell 创建具有现代体验 UI 的文档库或列表
SharePoint Online中的新列表和库体验通过提供导航、快速响应、移动UI、更易于使用等许多功能来改善用户体验。您可以随时在经典体验和新体验之间切换。以下是 PowerShell-CSOM 脚本,用于在 SharePoint Online 中创建具有新体验 UI 的文档库。
用于在新体验 UI 中创建文档库的 PowerShell 脚本:
您是否正在寻找一种方法来创建具有 SharePoint Online 全新体验的文档库?如果是这样,PowerShell 可以帮助您完成工作。
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/Projects"
$UserName="salaudeen@crescent.com"
$Password ="Password goes here"
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
Try {
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials
#Create new document library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = "Project Documents"
$ListInfo.TemplateType = 101 #Document Library
$List = $Context.Web.Lists.Add($ListInfo)
#Set "New Experience" as list property
$List.ListExperienceOptions = "NewExperience" #Or ClassicExperience
$List.Update()
$Context.ExecuteQuery()
Write-host "New Document Library Created!" -ForegroundColor Green
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
这将在现代新体验 UI 中创建一个新库“项目文档”。
PnP PowerShell 创建列表或文档库新体验
使用此 PnP PowerShell 创建具有 SharePoint Online 全新体验的文档库:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Projects"
$ListName = "Team Projects"
$ListTemplate ="DocumentLibrary"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Create a document library using pnp powershell
$List = New-PnPList -Title $ListName -Template $ListTemplate -ErrorAction Stop
#Set list experience
Set-PnPList -Identity $List -ListExperience NewExperience
Write-host "List '$ListName' Created Successfully!" -f Green
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
使用“GenericList”作为 $ListTemplate 在 SharePoint Online 中创建新的自定义列表。
