Скрипт завершает все выполняющиеся экземпляры РП и при необходимости выполняет перезапуск.
Иногда он выполняет рестарт даже если не указывать -restart, во избежание этого нужно закомментарить выделенный красным фрагмент.
Может также удалять старые выполняющиеся экземпляры РП. Отслеживать выполнение можно тут: _layouts/wrksetng.aspx?List=%7B8E4A6033%2DFD1B%2D4BBA%2DAE60%2D6D2869D3A28B%7D (ID списка ваш)
Пример использования:
Видим картинку, хотим удалить старые экземпляры процесса "Оповещения (предыдущая версия: 23.09.2011 14:01:26)"
Запускаем ./Cancel-SPWorkflow -site "https://skr.mts.ru/it/d/dpp/its" -List "Задачи" -Workflow "Оповещения (предыдущая версия: 23.09.2011 14:01:26)"
Дожидаемся окончания выполнения скрипта и видим:
##################################################################################
#
#
# Script name: Cancel-SPWorkflow.ps1
#
# Author: Mattias.Karlsson@zipper.se
# Homepage: www.mysharepointofview.com
#
#
##################################################################################
#
#
# Script name: Cancel-SPWorkflow.ps1
#
# Author: Mattias.Karlsson@zipper.se
# Homepage: www.mysharepointofview.com
#
#
##################################################################################
param([string]$site, [string]$List, [string]$Workflowname, [switch]$Restart, [switch]$IncludeRunning, [switch]$help)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function GetHelp() {
$HelpText = @"
DESCRIPTION:
NAME: Cancel-SPWorkflow
Cancel SharePoint Workflows and restart them if wanted
NAME: Cancel-SPWorkflow
Cancel SharePoint Workflows and restart them if wanted
PARAMETERS:
-Site Url to the SharePoint Site
-List Name of the list
-Workflowname Name of the workflow
-Restart Optional if you want to restart the workflows
-IncludeRunning Optional if you want to include running workflows
-help Displays the help topic
-Site Url to the SharePoint Site
-List Name of the list
-Workflowname Name of the workflow
-Restart Optional if you want to restart the workflows
-IncludeRunning Optional if you want to include running workflows
-help Displays the help topic
SYNTAX:
Cancel-SPWorkflow -help
Displays the help topic for the script
Cancel-SPWorkflow -help
Displays the help topic for the script
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow
Terminates all workflows with the specific workflow name
Terminates all workflows with the specific workflow name
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow -Includerunning
Terminates all workflows with the specific workflow name and include running workflows
Terminates all workflows with the specific workflow name and include running workflows
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow -restart
Terminates all workflows with the specific workflow name and then restart the workflow for all items
Terminates all workflows with the specific workflow name and then restart the workflow for all items
"@
$HelpText
$HelpText
}
function Get-SPSite([string]$site) {
New-Object Microsoft.SharePoint.SPSite($site)
}
New-Object Microsoft.SharePoint.SPSite($site)
}
function Get-SPWeb([string]$site) {
$SPSite = Get-SPSite $site
$SPSite.OpenWeb()
}
$SPSite.OpenWeb()
}
function Get-SPList([string]$site, [string]$List){
$OpenWeb = Get-SPWeb $site
$OpenWeb.Lists[$List]
}
$OpenWeb = Get-SPWeb $site
$OpenWeb.Lists[$List]
}
function CancelWF($site, $List, $Workflowname, [switch]$Restart, [switch]$IncludeRunning) {
$SPList = Get-SPList $site $List
Write-host $SPList.WorkflowAssociations
if(($SPList.WorkflowAssociations | where {$_.Name -eq $Workflowname}) -gt $null){
TerminateWF $site $List $Workflowname $Restart $IncludeRunning
}
else{
Write-host "The Specifed Workflow does not exist in the list"
}
}
if(($SPList.WorkflowAssociations | where {$_.Name -eq $Workflowname}) -gt $null){
TerminateWF $site $List $Workflowname $Restart $IncludeRunning
}
else{
Write-host "The Specifed Workflow does not exist in the list"
}
}
function StartWF($Site, $List, $Workflowname){
$SPList = Get-SPList $site $List
$WFAssociation = $SPList.WorkflowAssociations | where {$_.name -eq $Workflowname}
$SPList = Get-SPList $site $List
$WFAssociation = $SPList.WorkflowAssociations | where {$_.name -eq $Workflowname}
foreach($item in $SPList.items) {
$StartWorkflow = $SPList.Parentweb.site.workflowmanager.startworkflow($item, $WFAssociation, $WFAssociation.AssociationData)
}
}
$StartWorkflow = $SPList.Parentweb.site.workflowmanager.startworkflow($item, $WFAssociation, $WFAssociation.AssociationData)
}
}
function TerminateWF($Site, $List, $Workflowname, $Restart, $IncludeRunning) {
$SPList = Get-SPList $site $List
foreach($item in $SPList.items) {
$SPList = Get-SPList $site $List
foreach($item in $SPList.items) {
if($item.Workflows.count -gt 0){
foreach($Workflow in $item.workflows){
if(($SPList.WorkflowAssociations | where {$_.id -eq $Workflow.AssociationId}).name -eq $Workflowname){
if($IncludeRunning){
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($Workflow)
}
else{
if(($Workflow.Internalstate -ne "Running") -and ($Workflow.Internalstate -ne "Completed") -and ($Workflow.Internalstate -ne "Cancelled")) {
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($Workflow)
}
}
}
}
}
}
if($Restart){
StartWF $Site $List $Workflowname
}
Write-host "Operation completed successfully" $TerminatedWFs
}
foreach($Workflow in $item.workflows){
if(($SPList.WorkflowAssociations | where {$_.id -eq $Workflow.AssociationId}).name -eq $Workflowname){
if($IncludeRunning){
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($Workflow)
}
else{
if(($Workflow.Internalstate -ne "Running") -and ($Workflow.Internalstate -ne "Completed") -and ($Workflow.Internalstate -ne "Cancelled")) {
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($Workflow)
}
}
}
}
}
}
if($Restart){
StartWF $Site $List $Workflowname
}
Write-host "Operation completed successfully" $TerminatedWFs
}
if($help) { GetHelp; Continue }
if($Site -AND $List -AND $Workflowname) { CancelWF -Site $Site -List $List -Workflowname $Workflowname -Restart $Restart -IncludeRunning $IncludeRunning}
else{ GetHelp; Continue}
if($Site -AND $List -AND $Workflowname) { CancelWF -Site $Site -List $List -Workflowname $Workflowname -Restart $Restart -IncludeRunning $IncludeRunning}
else{ GetHelp; Continue}
Комментариев нет:
Отправить комментарий