Get All List Level 2013 Workflows Using Power shell in SharePoint Online

In this is post we will see how to Get All List Level 2013 Workflows using CSOM power shell  from  all the sub sites in a site collection in SharePoint online.

This post is the 6th post   in series of the  Power shell Scripts for Getting the data from site collection in SharePoint Online.

Get all Sub site details in Site Collection in SharePoint online using Power shell .

Get All Lists details in a site collection Using Power shell in SharePoint Online

Get All Lists items in a site collection Using Power shell in SharePoint Online

Get All Document details from all sites in a site collection Using Power shell in SharePoint Online

Get Check out Documents from all sites in a site collection Using Power shell in SharePoint Online

Note:  please check the  above links before this post before to proceed further , since this is  continuation of the first post and we are using the excel generated in the above post as an input for the script below.

Copy the below script to notepad and save the file with Get All List Level Workflows-2013.ps1

Copy the  Microsoft.SharePoint.Client.WorkflowServices.dll to the folder where you are saving the below scripts


#Add - PSSnapin Microsoft.SharePoint.PowerShell  

$host.Runspace.ThreadOptions = "ReuseThread" 

#Definition of the function that allows to create a new view in a SharePoint Online list 

function Get-ListWorkflowInfo-ByList
{
    param ($sCSOMPath,$sSiteID,$sSiteName,$sSiteUrl,$ListID,$ListTitle,$ListViewUrl,$BaseTemplate,$sUserName,$sPassword,$sWeburl,$FileName)
    try
    {
        #Adding the Client OM Assemblies
		$sCSOMPathdll=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"
        $sCSOMPathWorkflowdll=$sCSOMPath +  "\Microsoft.SharePoint.Client.WorkflowServices.dll"

        Add-Type -Path $sCSOMPathdll
        Add-Type -Path $sCSOMRuntimePath
		Add-Type -Path $sCSOMPathWorkflowdll 		

        #SPO Client Object Model Context
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl)
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)
		#$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)
        $spoCtx.Credentials = $spoCredentials       

		$web = $spoCtx.Web
		$List = $web.Lists.GetByTitle($ListTitle);

		$spoCtx.Load($web)
		$spoCtx.Load($List)
		$spoCtx.ExecuteQuery() 

		#$guid = [GUID]$ListID
		$workflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($spoCtx, $web);
		$workflowSubscriptionService = $workflowServicesManager.GetWorkflowSubscriptionService();
		$workflowAssociations = $workflowSubscriptionService.EnumerateSubscriptionsByList($List.Id);

        $spoCtx.Load($workflowAssociations);
        $spoCtx.ExecuteQuery();

		$associationname =""
		$AllowManual = ""
		$TaskListTitle =""
		$ObjectVersion =""
		$Enabled = ""
		$Created = ""
		$AutoStartCreate=""
		$AutoStartChange=""
		$AllWorkflows = @()

		foreach ($association in $workflowAssociations)
        {

          $associationname = $association.Name
		  $AllowManual = $association.AllowManual
		  $TaskListTitle = $association.TaskListTitle
		  $ObjectVersion = $association.ObjectVersion
		  $Enabled = $association.Enabled  #Gets or sets a value that specifies whether new workflow instances will be allowed for this workflow association
		  $Created = $association.Created	#Gets a value that specifies the date and time at which this workflow association was created.
		  $Modified = $association.Modified
		  $AutoStartCreate = $association.AutoStartCreate
		  $AutoStartChange = $association.AutoStartChange

			$AllWorkflows += New-Object -TypeName PSObject -Property @{
								SiteID = $sSiteID
								SiteName = $sSiteName
								SiteUrl =$sSiteUrl
                                ListID = $ListID
								ListTitle = $ListTitle
                                ListViewUrl =$ListViewUrl
								BaseTemplate= $BaseTemplate
								WorkflowName =$associationname
								AllowManual =    $AllowManual
								AutoStartCreate =  $AutoStartCreate
								AutoStartChange = $AutoStartChange
								TaskListTitle =  $TaskListTitle
								ObjectVersion =  $ObjectVersion
								Enabled = $Enabled
								Created =   $Created
								Modified =$Modified
            					} | Select  SiteName,SiteUrl,ListID,ListTitle,ListViewUrl,BaseTemplate,WorkflowName,AllowManual,AutoStartCreate,AutoStartChange,TaskListTitle,ObjectVersion,Enabled,Created,Modified
        }

		$AllWorkflows| Export-CSV ($sCSOMPath+"\"+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8

        $spoCtx.Dispose()
    }
    catch [System.Exception]
    {
        Write-Host -ForegroundColor Red $_.Exception.ToString()
		Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"
    }
} 

 function Get-ListItemInfo
{
    param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$sWeburl,$FileName,$ImportFile)
    try
    {
       	Write-Host "Getting All Lists Workflows in a Site Collection"
		Write-Host "------------------------------------------------"
        $ListBaseTemplate =@("101","110","111","112","113","114","116","121","122","123")

		$ListInfo = import-csv ($sCSOMPath+"\"+$ImportFile+".csv") #| Where {$_.ListTitle -contains "Change Request Log" } # $ListBaseTemplate -notcontains $_.BaseTemplate -And

		 write-host "List Info Cont -$($ListInfo.Count)"
		  for ($i = 0; $i -lt $ListInfo.Count; $i++)
		  {
			$List=$ListInfo[$i]

			Write-Host "$($i). List Title : $($List.ListTitle) :: Site: $($List.SiteUrl)"

			Get-ListWorkflowInfo-ByList -sCSOMPath $sCSOMPath -sSiteID $List.SiteID -sSiteName $List.SiteName -sSiteUrl $List.SiteUrl -ListID $List.ListID -ListTitle $List.ListTitle -ListViewUrl $List.ListViewUrl -BaseTemplate $List.BaseTemplate -sUserName $sUserName -sPassword $sPassword -sWeburl $sWeburl -FileName $FileName

		  }

		Read-Host -Prompt "file created Successfull..! in the following path $sCSOMPath, Press any key to close this window"

    }
    catch [System.Exception]
    {
        Write-Host -ForegroundColor Red $_.Exception.ToString()
		Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script -main"
    }
} 

$FileName = "Target_List_Workflow_Collection"     #Read-Host -Prompt "Enter File Name to write (eg: XXXXX)"
$ImportFileName= "Source_ListCollection"        #Read-Host -Prompt "Enter existing File Name to import file extension is csv (eg: YYYYY)"
$sWeburl = "https://tarun.sharepoint.com"               #Read-Host -Prompt "Enter Root Site URL (eg: http://Server:port/)"
$sSiteUrl = "https://tarun.sharepoint.com/sites/sharepointmates"           #Read-Host -Prompt "Enter Site Collection URL (eg: http://Server:port/Sites/Dev)"
$sUserName = "admin@tarun.onmicrosoft.com"                   #Read-Host -Prompt "Enter User Name"
$sPassword = ConvertTo-SecureString "XXXX" -AsPlainText -Force  #Read-Host -Prompt "Enter your password" -AsSecureString 

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath

Get-ListItemInfo -sCSOMPath $dir -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sWeburl $sWeburl -FileName $FileName -ImportFile $ImportFileName

  • Please update the  $sWeburl,$sUserName,$sPassword  and $sSiteUrl variables with your SharePoint online  environment.
  • In ImportFileName= “Source_ListCollection”,   Source_ListCollectionis the name of the  excel which contains the details of the  all list  details that was generated in the second post .  If you want to give the your custom file  as an input to the above script please create the excel with the  name Source_ListCollection and the excel sheet name Source_ListCollection  with structure as below

ListItemsexcelResultScreen

Or else you can use the second post to generate the excel

2) Now Right click on the Get All List Level Workflows-2013.ps1  Power shell script file and select Run with Power Shell

3) After Successful execution of the scripts we will get the below message

Get All List Level 2013 Workflows

4) Now go to the folder, we will find the excel file With name Target_List_Workflow_Collection .

For On premises we need to slightly change  $spoCredentials  and $sUserName    variables in the above script.

$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)

We need to give the user name along with domain name as below

 $sUserName = "2013dev\spadmin"

please change the  on premises site  collection url , web url  and password as well.

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s