3

I'm creating a number of sites using a powershell script. Now, when each of the sites is finished, I want to activate features on it.

My problem is that when I do this, it takes some time before the site is ready. Especially in SharePoint Online it is hard to predict when the site is ready. I've tried using time-loops, but I was wondering if there is a status setting somewhere that I can query instead.

Any thoughts?

miracules
  • 686
  • 7
  • 25
  • I don't think there's any property/status to predict whether or not site is ready to use. Sometimes back I had also faced a similar situation where I had to create a number of sites for Online in CSOM. There I ended up using a while loop where I, at certain time-interval, would query the url of the new site. You'll be receiving an error until your site's ready and responding. It used to take anywhere between 5-15 mins! – Piyush Oct 26 '15 at 11:16
  • 2
    Why this is downvoted beats me... it is a relevant question. – miracules Nov 02 '15 at 09:41

3 Answers3

2

Actually we solved the problem. The siteCreationOperation has a property named isComplete. Iterate over this and pick up the boolean for further processing :)

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)
    ...
miracules
  • 686
  • 7
  • 25
0

Here is something that worked for me:

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

Where admin URL is 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

-2

This will work but you are better testing for the site and then doing another loop to test for the last artifact that creates like a list or a library. I've only tested this on an on premise and not online instance

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

Cheers

Truez

Truezplaya
  • 1,315
  • 1
  • 13
  • 26