Created
August 16, 2016 05:28
-
-
Save aaira-a/816e888de1c7eb4568717c7a91574973 to your computer and use it in GitHub Desktop.
get all workflow versions in a site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 Web | |
$web = $clientContext.Web | |
$clientContext.Load($web) | |
$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 WorkflowDeploymentService | |
$WorkflowDeploymentService = $WorkflowServicesManager.GetWorkflowDeploymentService() | |
$clientContext.Load($WorkflowDeploymentService) | |
$clientContext.ExecuteQuery() | |
# Get WorkflowDefinitions | |
$WorkflowDefinitions = $WorkflowDeploymentService.EnumerateDefinitions($false) | |
$clientContext.Load($WorkflowDefinitions) | |
$clientContext.ExecuteQuery() | |
$i = 0; | |
$WorkflowDefinitions | Select-Object -InformationAction Inquire Selection, DisplayName,Id,RestrictToType | ForEach-Object {$_.Selection = $i++; $_} | out-host | |
$selectionWorkflow = Read-Host 'Which workflow do you select from above (Selection)?' | |
$WorkflowDefinitionId = $WorkflowDefinitions[$selectionWorkflow].Id.Guid -replace '[-]' | |
$uri = New-Object System.Uri($SiteUrl) | |
$wfUrl = $uri.AbsolutePath + "wfsvc/"+ $WorkflowDefinitionId +"/workflow.xaml" | |
$workflow = $web.GetFileByServerRelativeUrl($wfUrl) | |
$versions = $workflow.Versions | |
$web.Context.Load($workflow) | |
$web.Context.Load($versions) | |
$web.Context.ExecuteQuery() | |
$versions | Select-Object Created, @{Name="Version";Expression={ "{0}" -f ($_.VersionLabel) }}, @{Name="Url";Expression={ "{0}" -f ($SiteUrl + $_.Url) }} | out-host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment