码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2020-07-17 14:13:50      阅读:83      评论:0      收藏:0      [点我收藏+]

标签: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:
技术图片
 
 
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:\Documents\ListCreationTemplate.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)‘"
    }
    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

标签:http   sof   res   gas   connect   each   span   ESS   ad csv   

原文地址:https://www.cnblogs.com/Javi/p/13328966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!