Skip to content

Instantly share code, notes, and snippets.

@aaira-a
Created December 30, 2015 03:23
Show Gist options
  • Save aaira-a/0484595a017a99b8c62c to your computer and use it in GitHub Desktop.
Save aaira-a/0484595a017a99b8c62c to your computer and use it in GitHub Desktop.
get specific property from a workflow definition from a list on sharepoint online using powershell csom
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll”
#Specify tenant admin and site URL
$SiteUrl = "mysiteurl"
$ListName = "mylistname"
$UserName = "myusername"
$SecurePassword = ConvertTo-SecureString "mypassword" -AsPlainText -Force
#Bind to site collection
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$ClientContext.Credentials = $Credentials
$ClientContext.ExecuteQuery()
# Get List
$List = $ClientContext.Web.Lists.GetByTitle($ListName)
$ClientContext.Load($List)
$ClientContext.ExecuteQuery()
# Get WorkflowServicesManager
$WorkflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ClientContext, $ClientContext.Web)
$ClientContext.Load($WorkflowServicesManager)
$ClientContext.ExecuteQuery()
# Get WorkflowSubscriptionService
$WorkflowSubscriptionService = $WorkflowServicesManager.GetWorkflowSubscriptionService()
$ClientContext.Load($WorkflowSubscriptionService)
$ClientContext.ExecuteQuery()
# Get WorkflowSubscriptionCollection of List
$Subscriptions = $WorkflowSubscriptionService.EnumerateSubscriptionsByList($List.Id)
$ClientContext.Load($Subscriptions)
$ClientContext.ExecuteQuery()
# Get WorkflowDeploymentService
$WorkflowDeploymentService = $WorkflowServicesManager.GetWorkflowDeploymentService()
$ClientContext.Load($WorkflowDeploymentService)
$ClientContext.ExecuteQuery()
# Get WorkflowDefinition of First Element in WorkflowSubscriptionCollection
$WorkflowDefinition = $WorkflowDeploymentService.GetDefinition($Subscriptions[0].DefinitionId)
$ClientContext.Load($WorkflowDefinition)
$ClientContext.ExecuteQuery()
# Get mypropertyname in WorkflowDefinition Properties
$WorkflowDefinition.Properties["mypropertyname"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment