locked
How to get sharepoint 2013 workflow stages count using powershell script RRS feed

  • 问题

  • Hi,

    I need to get number of stages used inside the sharepoint 2013 workflow using powershell script.

    FYI I'm using SharePoint Designer 2013 with SharePoint 2016 On-Prem.

    I can able to get number of stages inside sharepoint 2010 workflow. Refer below code:

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    $workflowName
    $global:workflowName="Sample"

    Function GetXOMLFromWorkflowInstance($wfa)
    {
        [xml]$xmldocument =  $wfa.SoapXml
        $name = $xmldocument.FirstChild.GetAttribute("Name")
        $wfName = $name.Replace(" ", "%20")
        $global:workflowName= $name
       #$wfName="ManagerNotification"
        $webRelativeFolder = "Workflows/" + $wfName
        $xomlFileName = $wfName + ".xoml"
        $wfFolder = $wfa.ParentWeb.GetFolder($webRelativeFolder)
        $xomlFile = $wfFolder.Files[$xomlFileName]
       

        if ($xomlFile.Exists)
        {
            $xomlStream = $xomlFile.OpenBinaryStream()
            $xmldocument.Load($xomlStream)
            $xomlStream.Close()
            return $xmldocument.OuterXml
        }

        return $xomlFileName
    }

    Function LoadAllWFXoml ()
    {    Write-Host "Search Started" -ForegroundColor Green
        $siteCollectionURL = Get-SPSite("http://sharepoint2016/sites/SP")
        
        $mySite = Get-SPSite -Identity $siteCollectionURL  
        $myWebs = Get-SPWeb -Site $mySite -Limit All  
        $results = @()
        foreach ($myWeb in $myWebs)  
        {  
            Write-Host "Looking in WEB: "  $myWeb.Url -ForegroundColor Green  
            foreach ($myList in $myWeb.Lists)  
            { 
             $list = $myWeb.Lists[$myList.Title]
             $wfaColl = $list.WorkflowAssociations

              Foreach ($i in $wfaColl)
                 {
                 Write-Host $i
                     $xml = GetXOMLFromWorkflowInstance $i
                     #Write-Host $xml
                     $count = ([regex]::Matches($xml, "<SequenceActivity" )).count
                     if($count -gt 0)
                        {
                          Write-Host "=============================="
                          Write-Host "List Name :" $myList.Title
                          Write-Host "WorkFlow Name:" $global:workflowName
                          write-Host "Total Number Steps Used:" $count
                         
                          $RowDetails = @{  
                                "Site Collection"  = $siteCollectionURL  
                                "Site Name"              = $myWeb  
                                "List Name"        = $myList.Title  
                                "List URL"         = $myList.DefaultViewUrl 
                                "Workflow Name"    =   $global:workflowName
                                "Steps Used"        =    $count             
                            }  
                            $results += New-Object PSObject -Property $RowDetails 
                        }
                 }
            }
        }

         $myFileName = [Environment]::GetFolderPath("Desktop") + "\SDWF-" +  (Get-Date).ToString('MM-dd-yyyy') + ".csv"  
         $results | export-csv -Path $myFileName -NoTypeInformation
         Write-Host "Search Done" -ForegroundColor Green
    }
    LoadAllWFXoml

    Please help me out or provide any alternate way to achieve this.

    Thank You

    2020年7月23日 12:17

全部回复