简体   繁体   中英

PowerShell batch

I am reading data from CSV which is having 10000 items and creating on SharePoint list of items. I want to put that in batch using PnP PowerShell. Someone suggests to me batch functionality how to use it?

To confirm, your question is about performing actions in batches of max. 1000 items at a time while the input comes from a much larger CSV file.

For that, you can do like below:

# import the large (10000 items) csv file in a variable
$data = Import-Csv -Path '<your input Csv file>'

# now loop through that in batches of max. 1000 items
$counter = 0
while ($counter -lt $data.Count) {
    # determine the amount of rows to process
    $maxRows = [math]::Min(1000, $data.Count - $counter)
    # loop through the data array using indexing in batches of $maxRows size
    for ($index = 0; $index -lt $maxRows; $index++) {
        # perform your PnP* action here on each item
        # referenced by $data[$index + $counter]
    }
    # increment the main counter
    $counter += $maxRows
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM