在使用 powershell 创建站点时,有没有办法告诉它何时创建并准备好使用?

Is there a way to tell when a site is created and ready to use when creating it using powershell?

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

我的问题是,当我执行此操作时,站点准备就绪需要一些时间。尤其是在 SharePoint Online 中,很难预测网站何时准备就绪。我试过使用时间循环,但我想知道是否有我可以查询的某个地方的状态设置。

有什么想法吗?

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

  $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 
    }

干杯

特鲁兹

实际上我们解决了这个问题。 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)
    ...

这是对我有用的东西:

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 and the Properties.Url is the site I am looking for, so something like https://Contonso.sharepoint.com/sites/Test1