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     

        <#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
        Write-Host "Creating Columns....WAIT..." -ForegroundColor Yellow    
  • You could do multiple $clientContext.ExecuteQuery(). So you know when the server created the fields.
    – Mx.
    Oct 19, 2016 at 12:38
  • Using for instead of foreach and keeping $clientContext.ExecuteQuery() in the loop worked.
    – krishna
    Oct 21, 2016 at 16:03
  • Yea since the execution blocks the thread until SharePoint is finished :)
    – Mx.
    Oct 21, 2016 at 16:11

1 Answer 1


Try this

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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