Skip to content

Instantly share code, notes, and snippets.

@aaira-a
Last active April 28, 2016 05:20
Show Gist options
  • Save aaira-a/aa0e46e3762ffd0139ac0148a24efe97 to your computer and use it in GitHub Desktop.
Save aaira-a/aa0e46e3762ffd0139ac0148a24efe97 to your computer and use it in GitHub Desktop.
get specific property from a workflow definition including non-published from a context 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"
$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 WorkflowServicesManager
$WorkflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ClientContext, $ClientContext.Web)
$ClientContext.Load($WorkflowServicesManager)
$ClientContext.ExecuteQuery()
# Get WorkflowDeploymentService
$WorkflowDeploymentService = $WorkflowServicesManager.GetWorkflowDeploymentService()
$ClientContext.Load($WorkflowDeploymentService)
$ClientContext.ExecuteQuery()
# Get all WorkflowDefinitions from the context
$WorkflowDefinitionList = $WorkflowDeploymentService.EnumerateDefinitions($false)
$ClientContext.Load($WorkflowDefinitionList)
$ClientContext.ExecuteQuery()
$WorkflowDefinitionList | select DisplayName, Id, Published
# Get WorkflowDefinition from WorkflowDefinitionList
$WorkflowDefinition = $WorkflowDeploymentService.GetDefinition("guidstring")
$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