SharePoint Online创建带有随机日期和时间的日期列

时间:2018-07-30 20:18:42

标签: sharepoint-online

我当前正在进行SharePoint在线测试,其中列日期(日期和时间)为空。我需要使用powershell脚本在此列中填充随机日期和时间信息,以便填充此列。列表视图包含10,000多个项目。

1 个答案:

答案 0 :(得分:0)

我们可以将PowerShell与CSOM配合使用。

$cc = New-Object Microsoft.SharePoint.Client.ClientContext("https://tenant.sharepoint.com/sites/some-site")
$cc.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("user@tenant.onmicrosoft.com", (ConvertTo-SecureString "password" -AsPlainText -Force))

$list = $cc.Web.Lists.GetByTitle("some list")
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View><RowLimit>200</RowLimit></View>"

do
{
    $started = Get-Date
    $items = $list.GetItems($query)
    $cc.Load($items)
    $cc.ExecuteQuery()

    # It is important to update ListItemCollectionPosition of object $query with current position
    $query.ListItemCollectionPosition = $items.ListItemCollectionPosition

    if ($items.Count -eq 0) { break }

    for ($i = 0; $i -lt $items.Count; $i++)
    {
        # update columns as needed
        $items[$i]["date"]=Get-Date
        $items[$i].Update()
    }

    $cc.ExecuteQuery()
    Write-Host "Time elapsed: $((Get-Date) - $started)"
    # ListItemCollectionPosition is null if there is no other page
} while ($query.ListItemCollectionPosition -ne $null)