【问题标题】:Is there a way to tell when a site is created and ready to use when creating it using powershell?有没有办法在使用 powershell 创建站点时判断站点何时创建并准备好使用?
【发布时间】:2015-10-26 07:32:12
【问题描述】:

我正在使用 powershell 脚本创建多个站点。现在,当每个站点都完成后,我想激活它的功能。

我的问题是,当我这样做时,网站准备好需要一些时间。尤其是在 SharePoint Online 中,很难预测网站何时准备就绪。我尝试过使用时间循环,但我想知道是否有可以查询的状态设置。

有什么想法吗?

【问题讨论】:

  • 我认为没有任何属性/状态可以预测网站是否可以使用。有时我也遇到过类似的情况,我必须在 CSOM 中为 Online 创建多个站点。在那里,我最终使用了一个 while 循环,在该循环中,我会在某个时间间隔内查询新站点的 url。在您的网站准备就绪并做出响应之前,您将收到一条错误消息。过去需要 5-15 分钟!
  • 为什么这被否决击败了我......这是一个相关的问题。

标签: powershell sharepoint sitecollection


【解决方案1】:

实际上我们解决了这个问题。 siteCreationOperation 有一个名为 isComplete 的属性。对此进行迭代并获取布尔值以进行进一步处理:)

https://msdn.microsoft.com/en-us/library/microsoft.online.sharepoint.tenantadministration.tenant.createsite(v=office.15).aspx

    #Create the site using the properties
    $tenant.CreateSite($properties) | Out-Null
    ...
    ...
    $siteCreationOperation = $tenant.CreateSite($properties)
    $ctx.Load($siteCreationOperation)
    ...
    ...
    #Create the site in the tennancy
    ...
    ...
    do
    {
        ...
        ...
        $ctx.Load($siteCreationOperation)
        $ctx.ExecuteQuery()
        Write-Host $siteCreationOperation.IsComplete
        ...
        ...
    }
    ...
    while (!$siteCreationOperation.IsComplete)
    ...

【讨论】:

    【解决方案2】:

    这对我有用:

    Connect-SPOService -Url $adminUrl -Credential $credentials
    while ((Get-SPOSite -Filter "Url -like '*$($properties.Url)*'").Status -ne "Active")
    {
        Write-Host "." -NoNewline
        Sleep -s 10
    }
    

    管理 URL 是 https://Contonso-Admin.sharepoint.com,而 Properties.Url 是我要查找的站点,所以类似于 https://Contonso.sharepoint.com/sites/Test1

    【讨论】:

      【解决方案3】:

      这会起作用,但您最好先测试该站点,然后再执行另一个循环来测试最后一个创建类似列表或库的工件。我只在本地而不是在线实例上对此进行了测试

        $site = Get-SPSite <Site here> -ErrorVariable err -ErrorAction SilentlyContinue -AssignmentCollection $assignmentCollection
      
          if($err)
          {
              while($err)
              {
                  Write-Host "Waiting for site to be created"
                  Start-Sleep -seconds 5
                  $site = Get-SPSite <site here>  -ErrorVariable err -ErrorAction SilentlyContinue -AssignmentCollection $assignmentCollection
              }
               #while loop for the last artifact that you are waiting for as the site will create but it may not be fully ready 
          }
      

      干杯

      真人

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-23
        • 1970-01-01
        • 2013-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多