【问题标题】:SharePoint online create a date column with random date and timeSharePoint Online 创建具有随机日期和时间的日期列
【发布时间】:2018-07-31 10:37:32
【问题描述】:

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

【问题讨论】:

    标签: sharepoint-online


    【解决方案1】:

    我们可以使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 2018-09-16
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      相关资源
      最近更新 更多