1

I am creating Site Columns on SharePoint Online via PowerShell scripts by taking field xml data from an xml file, unable to figure out how to show progress of Site Columns creation as there are around 100+ fields and console is static for a very long time. Below is the PowerShell script code.

.....
.....
    $web = $site.RootWeb   
        $fields = $web.Fields     
        $clientContext.Load($web)  
        $clientContext.Load($fields)     
        $clientContext.ExecuteQuery() 

        <#Import field xml from SiteColumnsData.xml file#>
        Write-Host "Getting fields from XML file" -ForegroundColor Magenta
        [xml]$s = Get-Content -Path ".\SiteColumnsDataTest.xml"
        $fieldslist = $s.SelectNodes("/SiteColumns/Fields/Field")
        $fieldslist | Foreach-Object {

            $fieldName = $fieldslist.Name
            Write-Host "Current Field is" $fieldName

        $field = $_.OuterXml.ToString()

        $fields.AddFieldAsXml($field, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView) | Out-Null
        $clientContext.Load($fields)   
        }
        Write-Host "Creating Columns....WAIT..." -ForegroundColor Yellow    
        $clientContext.ExecuteQuery()
....
.....
  • You could do multiple $clientContext.ExecuteQuery(). So you know when the server created the fields. – Mx. Oct 19 '16 at 12:38
  • Using for instead of foreach and keeping $clientContext.ExecuteQuery() in the loop worked. – krishna Oct 21 '16 at 16:03
  • Yea since the execution blocks the thread until SharePoint is finished :) – Mx. Oct 21 '16 at 16:11
0

Try this

Write-Progress -Activity 'Creating Columns' -Status $fieldName;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.