首页 > 其他专区 > SharePoint >

SharePoint PowerShell 启动工作流

SharePoint 2021-09-22 09:42:05

最近,有个需求,就是需要批量更新列表内容,平时这些操作,都用powershell去完成,但是,powershell需要在服务器上操作,而服务器权限需要通过客户的层层把关,所以,这次就考虑不用命令了,而改用SharePoint网站工作流,然后,用powershell命令去创建任务计划。

  这样,以后有需求修改,直接在客户端就能做了,而任务计划,是始终不会变的。

  1.创建网站工作流,这个就比较简单了,我们就不多少了,直接在SharePoint Designer里干就好了;

  2.启动网站工作流的PowerShell代码段,这个显然是本文的重中之重;


复制代码
# SharePoint.Workflow.Start-SPSiteWorkflow

param (
[string]$Url = "http://sharepoint/demos/workflow",
[string]$Workflow = "Sample Site Workflow"
)

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction
SilentlyContinue
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

# get the workflow assocation from the target site/web
$site = Get-SPSite $Url
$culture = [System.Globalization.CultureInfo]::InvariantCulture
$wfAssociation = $site.RootWeb.WorkflowAssociations.GetAssociationByName($Workflow,$culture)

if ( $wfAssociation )
{
# initialize and optionally update association data
$assocData = $wfAssociation.AssociationData

# start the workflow
$wfRunOption = [Microsoft.SharePoint.Workflow.SPWorkflowRunOptions]::Asynchronous
$site.WorkflowManager.StartWorkflow($site, $wfAssociation, $assocData,$wfRunOption)
}
else
{
Write-Error "Workflow association not found on target web site."
}

复制代码

  3.保存成ps1文件,然后,创建一个任务计划定时去执行就好了;

  4.创建任务计划可以参考:

  http://www.office9.cn/upload/20210922/10341253.html  结束语

  SharePoint的好处就在于是个平台,很多功能有多种多样的方式来完成,而我们可以根据需求,选中最最适合我们场景的那一个。

  当然,这些就需要我们对SharePoint有这深入的了解,方方面面的功能都很熟悉了。


标签: PowerShell启动工作流

office教程网 Copyright © 2016-2020 https://www.office9.cn. Some Rights Reserved.