我使用powershell脚本创建了许多网站。现在,当每个站点都完成后,我想激活它上面的功能。
我的问题是,当我这样做时,在网站准备好之前需要一些时间。特别是在SharePoint Online中,很难预测网站何时准备就绪。我尝试过使用时间循环,但我想知道某个地方是否有可以查询的状态设置。
有什么想法吗?
答案 0 :(得分:1)
实际上我们解决了这个问题。 siteCreationOperation有一个名为isComplete的属性。迭代这个并获取布尔值以进行进一步处理:)
#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)
...
答案 1 :(得分:0)
这对我有用:
Connect-SPOService -Url $adminUrl -Credential $credentials
while ((Get-SPOSite -Filter "Url -like '*$($properties.Url)*'").Status -ne "Active")
{
Write-Host "." -NoNewline
Sleep -s 10
}
其中管理员网址为https://Contonso-Admin.sharepoint.com且Properties.Url是我要查找的网站,因此类似https://Contonso.sharepoint.com/sites/Test1
答案 2 :(得分:-2)
这将有效,但您最好测试该网站,然后再进行另一个循环测试最后创建的工件,如列表或库。我只是在本地而非在线实例上测试了这个
$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
}
干杯
Truez