Wednesday, October 12, 2016

SharePoint Online - Get workflow status in List Item using PowerShell

Requirement was for SharePoint online tenant to get the workflow status in list item.
I choose to write quick PowerShell script using CSOM to achieve this.

 Function Get-SPOCredentials([string]$UserName,[string]$Password)  
   if([string]::IsNullOrEmpty($Password)) {  
    $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString   
   else {  
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force  
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)  
  Function GetWorkflowStatus([Microsoft.SharePoint.Client.List]$list,[int]$listItemId, [string]$workflowName)  
    $context = $list.Context  
    $listItem = $list.GetItemById($listItemId)  
    $workflowStatusField = $listItem.ParentList.Fields.GetByTitle($workflowName)  
    if ($listItem.FieldValuesAsHtml[$workflowStatusField.StaticName] -ne $null)  
      $statusValue = $listItem.FieldValuesAsHtml[$workflowStatusField.StaticName]  
      return $statusValue;  
    return $null  
 $UserName = ""  
 $Password = Read-Host -Prompt "Enter the password"    
 $WebUrl = ""  
 $ListTitle = "MySPList"  
 $ListItemId = 1  
 $WorkflowTitle = "Approval"  
 $Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)  
 $Context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password  
 $list = $Context.Web.Lists.GetByTitle($ListTitle)  
 $statusValue = GetWorkflowStatus -list $list -listItemId $ListItemId -workflowName $workflowTitle  

Hope this handy script will save your time!


  1. Hi Anuja,
    Do you have script to list down all the workflows in my SharePoint Online tenant?

  2. It is throwing an error at $context.Load($listItem.FieldValuesAsHtml)

    Error : Cannot find an overload for "Load" and the argument count: "1"