SharePoint Online: Create Multiple Lists from a CSV File using PowerShell

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SharePoint Online: Create Multiple Lists from a CSV File using PowerShell相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/http' title='http'>http   sof   res   gas   connect   each   span   ESS   ad csv   

How to Create Multiple lists from CSV File?

We can use the combination of CSV and PowerShell to create multiple lists in bulk in SharePoint Online. Here is my CSV File:
鎶€鏈浘鐗? src=
 
 
PowerShell to Create Multiple lists from CSV File

Use this PnP PowerShell to create SharePoint lists from csv.

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$CSVFilePath = "C:DocumentsListCreationTemplate.csv"
   
#Connect to the site
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Get the data from CSV file
$CSVFile = Import-CSV $CSVFilePath
   
#Read CSV file and create List
ForEach($Row in $CSVFile)
{
    Try {
        #Create List
        Write-host -f Yellow "Creating List:"$Row.ListName
        If($Row.OnQuickLaunch -eq "True")
        {
            New-PnPList -Title $Row.ListName -Template $Row.Template -OnQuickLaunch -ErrorAction Stop | Out-Null
        }
        else
        {
            New-PnPList -Title $Row.ListName -Template $Row.Template -ErrorAction Stop | Out-Null
        }
        Write-host -f Green "`tCreated List 鈥?($Row.ListName)鈥?/span>"
    }
    Catch {
        write-host -f Red "`tError:" $_.Exception.Message
    }
}

 

 
This CSV file has ListName, Description, Template, OnQuickLaunch columns. You can add any necessary columns as the parameter for creating list.
 
Tail: How to Get All Values from an Enumerator?
If you want get all values from an enum, use the below PowerShell script. In my case, I had to retrieve all list template types.
 
#Get All Values from the Enum
Function Get-EnumValues([string]$Enumerator)
{
    $EnumValues = @{}
    [Enum]::GetValues([Type]$Enumerator) | ForEach-Object {
        $EnumValues.add($_, $_.value__)
    }
    $EnumValues
}
Get-EnumValues -Enumerator "Microsoft.SharePoint.Client.ListTemplateType"

 



以上是关于SharePoint Online: Create Multiple Lists from a CSV File using PowerShell的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint On Premise/ SharePoint Online增强格式的文本栏

SharePoint Online 创建网站集

Sharepoint online P2计划2的价格调整

SharePoint Online 创建网站

SharePoint Online和SharePoint 2016 导出到Excel 表错误

SharePoint Online 触发Teams审批