This script sets up a function to add a workflow association to a specifically named list or document library in all sites of a site collection. For example, adding a workflow to the “Pages” document library in all publishing sites. You use the function by first running the script and then calling it using the following command:
AddWorkflowToLibraries -SiteCollection http://portal -ListName Pages -WfName "Collect Feedback - SharePoint 2010" -WfAssociationName "Collect Feedback"
The example above adds the out-of-box SharePoint 2010 Collect Feedback workflow to the Pages library in each site of the http://portal site collection, calling it “Collect Feedback”. If a site does not have a Pages library (e.g., a Team site), the script will pass over it and continue on to the next site. The script will also continue to the next site if the workflow already exists in the list and I have added an optional delete section (commented out in the script below) which you can use to delete a workflow associated with each list – this will allow you to bulk delete workflow associations before creating new ones.
Run this script first before typing the AddWorkflowToLibraries command above:
function AddWorkflowToLibraries ($SiteCollection, $ListName, $WfName, $WfAssociationName)
{#Get site object and create blank guid to store workflow template ID
$site = Get-SPSite $SiteCollection
[Guid]$wfTemplateId = New-Object Guid#Step through each web in site collection
$site | Get-SPWeb -limit all | ForEach-Object {#Do the following if a list exists with the name specified by the user - e.g., Pages
if ($_.Lists[$ListName]) {write-host $_.Title"has a list called"$ListName -ForegroundColor green
$list = $_.Lists[$ListName]
#Go through each workflow installed in the site to find the correct ID
foreach ($wfTemplate in $_.WorkflowTemplates) {
if ($wfTemplate.Name -eq $WfName) {
$wfTemplateId = $wfTemplate.Id
}
}
#Set up the template from the ID found
$wfTemplate = $_.WorkflowTemplates[$wfTemplateId]
#Check if the site already has a workflow history list - if not, create it
if(!$_.Lists["Workflow History"])
{
$_.Lists.Add("Workflow History", "A system library used to store workflow history information that is created in this site. It is created by the Publishing feature.",
"WorkflowHistory", "00BFEA71-4EA5-48D4-A4AD-305CF7030140", 140, "100")
if (!$_.Features["00BFEA71-4EA5-48D4-A4AD-305CF7030140"]) {
Enable-SPFeature -Identity WorkflowHistoryList -Url $_.Url
}
$wfHistory = $_.Lists["Workflow History"]
$wfHistory.Hidden = $true
$wfHistory.Update()
}
else
{
$wfHistory = $_.Lists["Workflow History"]
}
#Check if the site already has a workflow tasks list - if not, create it
if(!$_.Lists["Workflow Tasks"])
{
$_.Lists.Add("Workflow Tasks", "This system library was created by the Publishing feature to store workflow tasks that are created in this site.", "WorkflowTasks", "BF611337-1591-49f4-BF42-CE7BE53852D8", 107, "100")
}
$wfTasks = $_.Lists["Workflow Tasks"]
#Set up workflow association (extra associated data can be added if you have it)
$wfAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($wfTemplate, $WfAssociationName, $wfTasks, $wfhistory)
#Check to see if the association has already been added to the list
[guid]$wfId = New-Object Guid
[bool]$wfFound = $false
foreach ($wf in $list.WorkflowAssociations) {
if ($wf.Name -eq $wfAssociation.Name) {
$wfId = $wf.Id
write-host "Workflow"$wf.Name"already exists on"$list.Title"list in site"$_.Title -ForegroundColor green
$wfFound = $true
}
}
#If association is already there, ignore the add (and optionally delete it)
if ($wfFound -eq $true) {
#Command to remove existing workflow from list before adding new one, if required
#$list.WorkflowAssociations.Remove($wfId)
#write-host "Removed workflow"$wfAssociation.Name"from"$list.Title"in site"$_.Title -ForegroundColor green
}
#else, add it to the workflow association to the list
else
{
$list.WorkflowAssociations.Add($wfAssociation)
write-host "Added workflow"$wfAssociation.Name"to"$list.Title"in site"$_.Title -ForegroundColor green
}
}
#Report if the site does not have the list specified by the user
else {
write-host $_.Title"does not have a list called"$listName -ForegroundColor green
}
}
#Dispose of Site object
$site.Dispose()
}
Another thing to note here are the names of the history and task lists associated with the workflow. I have gone with “Workflow History” and “Workflow Tasks” but you can change these as required. The script will create these lists if they do not exist already on a site (e.g., when a Publishing site template is used without the approval workflow).
Phil, you're my hero! I have 2 items to add:
ReplyDeleteThis will allow you to auto start workflows--
line 52 [bool]$wfFound = $false
new $wfAssociation.AllowManual = false;
new $wfAssociation.AutoStartChange = true;
new $wfAssociation.AutoStartCreate = true;
line 53 foreach ($wf in $list.WorkflowAssociations) {
I had to change "Workflow Tasks" to just "Tasks" between lines 43 and 47. IDK why, but once I did that everything worked out great. Thanks again for your site and your smarts!
Hi,
DeleteCan U please help me how can I set 'assign to' and 'cc' fields for collect feedback workflow using powershell.
Thank you Phil.
ReplyDeleteThis script helped me a lot.
Keep posting such a great information
Phil, I am trying to figure out whether to customize the OOB Publishing Approval workflow, or copy and modify as a new WF. All I need to do is add a 2nd level of approval to the existing WF.
ReplyDeleteIf I copy and modify, how do I make my new WF the default for all the Publishing assets (pages, master pages, page layouts, etc.)? I am a bit confused as to how the association is done with the OOB Publishing Approval WF.
I also have a current thread on StackOverflow.com with this question (http://is.gd/Dm1SHy)
Phil, this script looks very close to what I'm trying to achieve, which is to add a new workflow to each site created under a specific site. i.e. in simple terms, I have a site collection with two sites: marketing and support. I've created a new workflow call 'support approval', and I want this added to every site created under 'support'. I'll work to see if this is possible, by altering your script.. but.....
ReplyDelete.. I've no idea how to run this script! I can launch SharePoint PowerShell, and can type in short scripts (4 or 5 lines), but the prospect of typing this size of a script by hand is daunting to say the least. I'm pretty sure it's possible to create script and run execute them via PowerShell, but haven't been able to find any websites that explain how.
Any ideas where I can find such instruction?
Kevin - Yes, this site!
ReplyDeleteRead this article:
http://get-spscripts.com/2010/06/windows-powershell-ise.html
I never use the standard command prompt based version of PowerShell. Windows PowerShell ISE is built into PowerShell 2.0 by Microsoft, allows you to copy and paste into a script window, and includes debugging features.
Wonderful! Thanks, Phil. I should have guessed you'd have an article on this too. Many thanks :)
ReplyDeleteI have a workflow I've made and promoted to reusable and globally reusable however I cannot get it to deploy to all of the subsites of a collection using your script. What needs to be changed in the script to apply my workflow to my collection? Here is the error I receive:
ReplyDeleteException calling "CreateListAssociation" with "4" argument(s): "Value cannot be null."
At C:\Users\csmith5\Desktop\workflow.ps1:49 char:106
+ $wfAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation <<<< ($wfTemplate, $WfAssociationName, $wfTasks, $wfhistory)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Phil,
ReplyDeleteAwesome post, thanks. Would it be possible to be able to set more options that are on the association form like "End on First Reject" or "End on Document Change"?
Thank you so much for sharing, Phil
ReplyDeleteNote: I have changed as "Anonymous Dec 15, 2010 08:05 PM" and it worked for me, thank you too, Annonymous
Phil,
ReplyDeleteI have this script that updates every item in one list. I have a problem, when I add a element into this list, this script executes and the workflow asociated too. How can I disable the automatic execution of this script asociated to list?
Add-PSSnapin "Microsoft.Sharepoint.Powershell"
$site = Get-SPWeb -identity "http://mywebsite"
$list = $site.Lists["List"]
$spitems = $list.items
foreach($item in $spitems){
[Microsoft.SharePoint.SPListItem]$spListItem = $item
$spListItem.Update();
}
Remove-PSSnapin -name "Microsoft.Sharepoint.Powershell"
Thanks for the great post. How do I set this workflow to start when an item is published, make it the default content publishing workflow?
ReplyDeleteI am running bellow script and when running first one getting error.The term 'AddWorkflowToLibraries' is not recognized as the name of a cmdlet, fu
ReplyDeletenction, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At C:\FMICPageApprovalWorkflow.ps1:1 char:23
+ AddWorkflowToLibraries <<<< -SiteCollection http://mosspa/ -ListName Pages -
WfName "Page Approval Workflow" -WfAssociationName "Page Approval Workflow"
+ CategoryInfo : ObjectNotFound: (AddWorkflowToLibraries:String)
[], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Hi Phil.
ReplyDeleteIts reduced huge time because i configure the workflow more than 20 lists manually.
This script helped me a lot.
Thank you very much.
Do you know how to add a workflow in a site? I deploy a workflow in a site collection but cannot deploy it on a site. The workflow template is simply missing in workflow settings.
ReplyDelete2015-12-7 xiaozhengm
ReplyDeleteugg boots
hollisters
michael kors handbags
nike free runs
sac longchamp pas cher
christian louboutin outlet
true religion
gucci borse
fitflop uk
christian louboutin
michael kors
michael kors outlet
ralph lauren uk
cheap uggs on sale
barbour uk
jordan 4
juicy couture
jordan 6
michael kors outlet
ed hardy outlet
ralph lauren pas cher
nike shoes
gucci outlet
ray ban sunglasses
michael kors outlet online
coach factory outlet
christian louboutin outlet
mizuno running shoes
oakley vault
nike roshe run women
cheap jordans
ugg boots
coach outlet
michael kors
nike outlet store
michael kors outlet online
coach outlet
jordan 13
pandora charms
coach outlet
Great Article..
ReplyDeleteOnline DotNet Training
.Net Online Training
Dot Net Training in Chennai
IT Training in Chennai
20160301meiqing
ReplyDeletethe north face jackets
abercrombie & fitch
louis vuitton outlet online
nike air huarache
michael kors
oakley sunglasses
cheap jerseys
ugg boots
tods outlet
north face outlet
hollister
uggs on sale
michael kors outlet
oakley outlet
michael kors handbags
cheap jordans
toms shoes
polo ralph lauren outlet
michael kors outlet
ray ban outlet
true religion jeans
michael kors outlet
louis vuitton
ray-ban sunglasses
retro jordans
canada goose jackets
michael kors online
abercrombie
kate spade handbags
coach factory outlet
louis vuitton outlet
louis vuitton outlet
oakley sunglasses
gucci bags
cheap oakleys
tory burch handbags
ray ban sunglasses outlet
louis vuitton
cheap uggs
jianbin0309
ReplyDeletetrue religion jeans outlet
celine outlet
louis vuitton handbags outlet
air jordan shoes for sale
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
tiffany outlet
swarovski crystal
michael kors outlet store
michael kors clearance
hermes bags
ray ban sunglasses
marc jacobs
valentino outlet
swarovski crystal
mac cosmetics
cheap nba jerseys
ray ban sunglasses
louis vuitton handbags outlet
ray-ban sunglasses
michael kors outlet store
michael kors outlet online
swarovski outlet
chicago blackhawks
true religion canada
michael kors outlet
ed hardy clothing
longchamp handbags outlet
prada outlet
ralph lauren shirts
michael kors factory store
cheap nfl jersey
rolex watches for sale
cheap nike shoes
mbt shoes outlet
fitflops uk
ReplyDeletelululemon pants
michael kors handbags
air force 1 shoes
adidas wings shoes
ralph lauren pas cher
true religion jeans
michael kors handbags outlet
pandora jewelry
ray-ban sunglasses
coach outlet
beats by dr dre
louis vuitton sunglasses for women
ferragamo shoes
longchamp solde
ray ban sunglasses
fitflops sale
fitflops uk
chaussure louboutin
ralph lauren pas cher
cheap jordan shoes
true religion uk outlet
ralph lauren outlet
coach outlet
true religion outlet
true religion jeans
replica watches
michael kors uk
michael kors handbags sale
longchamp outlet
cai20160519
louis vuitton
ReplyDeletecoach factory outlet
ray ban sunglasses outlet
coach factory outlet
rolex submariner watches
louis vuitton handbags
louis vuitton outlet
toms outlet
jordans
ray ban sunglasses
ralph lauren polo
cartier watches
oakley sunglasses
rolex watches
louis vuitton handbags
pandora jewelry
ralph lauren uk
true religion jeans
ray ban sunglasses
burberry outlet
jordan 3 infrared
cheap jordans
michael kors handbags
fitflops
coach outlet online
cheap ray ban sunglasses
abercrombie outlet
louis vuitton outlet
basketball shoes
jordan shoes
longchamp handbags
michael kors handbags
true religion outlet
burberry outlet online
michael kors handbags
adidas trainers
adidas originals
abercrombie and fitch
adidas outlet
tods shoes
20168.8wengdongdong
for beginners like me need a lot of reading and searching for information on various blogs. and articles that you share a very nice and inspires me .
ReplyDeleteobat aborsi
jual obat aborsi
polo ralph lauren shirts
ReplyDeletemichael kors outlet online
hogan sito ufficiale
jordan shoes
michael kors outlet clearance
nba jerseys
rolex watches for sale
toms outlet
louis vuitton handbags
uggs on sale
20169.27chenjinyan
coach factory outlet
ReplyDeleteair max uk
adidas outlet store
ray ban sunglasses
north face outlet
ugg uk
cheap ugg boots
cheap nba jerseys
hermes scarf
clippers jerseys
2016.11.26xukaimin
michael kors outlet
ReplyDeletenike air force 1
coach outlet store
louis vuitton outlet
ugg boots uk
coach outlet
mulberry handbags
uggs on sale
mcm outlet
true religion uk outlet
20161130caihuali
celine handbags
ReplyDeletehollister clothing
ralph lauren outlet
ray ban sunglasses
oakley sunglasses
louis vuitton outlet online
timberland outlet
jordan 13
true religion jeans
coach outlet
20173.9chenjinyan
By reading this article many benefits that we can learn. thank you for sharing your insights to us all . boneka full body
ReplyDeleteHi Phil,
ReplyDeleteYou have not added the script for setting the 'assign to' and cc fields for collect feedback approval. Can you Please share that script?
cheap oakley sunglasses
ReplyDeletenhl jerseys
vans store
ralph lauren outlet
ed hardy shirts
michael kors handbags
true religion outlet
air jordan shoes
ray ban eyeglasses
air jordan shoes
2017.5.15chenlixiang
This is a very good article material and it is very useful for us all. thank you . cara menggugurkan kandungan
ReplyDeleteThis blog is a great source of information which is very useful for me.
ReplyDeleteJual Obat Aborsi Pekanbaru
Jual Obat Aborsi Bekasi
Jual Obat Aborsi malang
Jual Obat Aborsi
Obat Aborsi semarang
Obat Aborsi yogyakarta
Obat Aborsi solo
Obat Aborsi
-Can be very slow but shows all backlinks along with their PR, Anchor and if it's a Nofollow
This blog is a great source of information which is very useful for me.
ReplyDeleteJual Obat Aborsi Pekanbaru
Jual Obat Aborsi Bekasi
Jual Obat Aborsi malang
Jual Obat Aborsi
Obat Aborsi semarang
Obat Aborsi yogyakarta
Obat Aborsi solo
Obat Aborsi
-Can be very slow but shows all backlinks along with their PR, Anchor and if it's a Nofollow
The article was very nice and very interesting to read. Thank you for sharing the information
ReplyDeleteObat Untuk Mengatasi Perut Kembung
Obat Ulu Hati Terasa Sesak
Obat Pendarahan Usus
Obat Maag Ringan
Obat Ginjal Berkista
Pengobatan Alternatif Radang Sendi
Jual obat aborsi pontianak
ReplyDeleteJual obat aborsi cimahi
Jual obat aborsi samarinda
Jual obat aborsi deli serdang
Jual obat aborsi cytotec
Jual obat aborsi jakarta
Jual obat aborsi banda aceh
Jual obat aborsi ternate
Jual obat aborsi batam
Jual obat aborsi pemalang
ReplyDeleteJual obat aborsi madiun
Jual obat aborsi sorong
Jual obat aborsi ambon
Jual obat aborsi mataram
Jual obat aborsi jayapura
Jual obat aborsi tangerang selatan
Jual obat aborsi semarang
Jual obat aborsi tanjung pinang
Jual obat aborsi tebing tinggi
ReplyDeleteJual obat aborsi kendal
Jual obat aborsi medan
Jual obat aborsi sragen
Jual obat aborsi tegal
Jual obat aborsi tangerang
Jual obat aborsi palembang
Jual obat aborsi karawang
Jual obat aborsi sumatra barat
Jual obat aborsi cikampek
Jual obat aborsi
ReplyDeleteJual obat aborsi bengkulu
Jual obat aborsi hongkong
Jual obat aborsi banyuwangi
Jual obat aborsi indramayu
Jual obat aborsi bandung
Jual obat aborsi mojokerto
Jual obat aborsi pekanbaru
Jual obat aborsi cilegon
nice more info
ReplyDeletethanks for sharing
ReplyDelete2、
ReplyDeletechristian louboutin outlet
nike outlet
nike outlet store
adidas outlet store
christian louboutin outlet
coach outlet online
coach factory store
cheap jordan shoes
christian louboutin
coach factory outlet
Thank you for joining us. his article is very helpful
ReplyDeleteObat Maag Alami
Obat Keputihan Alami
Cara Mengobati Hematuria
Obat Penambah Berat Badan
Cara Mengobati Penyakit Kista
Cara Mengobati Sesak Napas Alami
thank you very useful information admin, and pardon me permission to share articles here may help :
ReplyDeleteCara mengatasi kulit melepuh
Obat kebas tangan dan kaki
Obat linu persendian
Obat penyubur kandungan agar cepat hamil
Cara menyembuhkan jantung bengkak
Obat amandel tradisional
Obat batuk berdarah ampuh
thanks fore sharing
ReplyDeleteat this time I will share articles about health hopefully can be useful for everyone.
ReplyDeleteMengobati Cacar Air Dengan Herbal
Bahaya Penyakit Kanker Payudara
This article is interesting and useful. And let me share an article about health which insha Allah will be very useful if we use it again for others.
ReplyDeleteCara Mengobati Penyakit Gula Darah
Obat Untuk Penyakit TBC
Cara Mengobati Jamur Mulut
Cara Pemesanan QnC Jelly Gamat
Cara Mengobati Telinga Berair
Bahaya Penyakit Muntaber dan cara mengatasinya
thank you very useful information admin, and pardon me permission to share articles here may help :
ReplyDeleteCara menyembuhkan gagal jantung
Cara menyembuhkan paru paru basah
Cara menyembuhkan gerd
Cara menyembuhkan diare
Obat herbal diare
Obat herbal penyakit kaki gajah
Obat muntaber herbal
Our digital marketing course in Chennai is targeted at those who are desirous of taking advantage of career opportunities in digital marketing. Join the very best Digital Marketing Course in Chennai. Get trained by an expert who will enrich you with the latest digital trends.
ReplyDeleteDigital Marketing Course in Chennai
Digital Marketing Training in Chennai
Online Digital Marketing Training
SEO Training in Chennai
Digital Marketing Course
Digital Marketing Training
Digital Marketing Courses
20181018 xiaoou
ReplyDeletepandora charms
pandora jewelry outlet
christian louboutin sale
coach outlet
cheap jordan shoes
kate spade handbags
cheap ray ban sunglasses
ugg outlet online
coach outlet online
kate spade outlet online
cheap nfl jerseys
ReplyDeletecheap jerseys
cheap jerseys from china
wholesale jerseys
cheap nfl jerseys from china
china jerseys
nfl jerseys china
wholesale nfl jerseys
cheap authentic nfl jerseys
cheap jerseys online
cheap authentic jerseys
cheap sports jerseys
cheap wholesale jerseys
china wholesale jerseys
discount nfl jerseys
cheap authentic jerseys from china
discount jerseys
custom cowboys jersey
nfl jerseys cheap
cheap nfl jerseys china
authentic nfl jerseys
الذباب من الحشرات التي تسبب الإزعاج للجميع بلا استثناء نظراً لصوتها المزعج بشكل ملحوظ إلا أن الأضخم الأضرار والعدوى التي تسببها فهي اكثر الحشرات التي تقوم بنقل الأمراض نتيجة لـ تواجدها في الأماكن المتسخة طول الوقت وبين القمامة وبين جميع الاتساخات.
ReplyDeleteشركة مكافحة حشرات بالطائف
شركة رش مبيدات بالطائف
المبيدات الحشرية الكيميائية
شركة الانوار لرش المبيدات
loke
ReplyDeleteobat Aborsi tangerang
obat Aborsi bali
ReplyDeletejual obat Aborsi
jual obat Aborsi surabaya
jual obat aborsi surabaya
No matter what type of Michael Kors Bags Outlet each individual got, they all had one thing in common. We all know that getting something on sale is like winning a mini lottery, but to find a name brand handbag like Michael Kors Black Friday Sale for instance, discounted is like a slice of heaven on earth. I have personally attacked my husband with hugs and kisses when finding Official Coach Outlet Online at discounted prices.
ReplyDeleteMichael Kors Factory Outlet stores can be found in malls all over. MK Outlet and other Coach merchandise can also be found in some boutiques. Inspired by the same material baseball gloves are made from, these Coach Bags On Sale Online are versatile and stylish. Since it's conception, the Michael Kors Handbags Outlet has been produced into a variety of designs, colors, shapes, and styles that have won top pick of millions of women the world over.
New Michael Kors Bags are the most sought after handbag. Since Coach Outlet Online is one of the most recognized name brands in the world of fashion, you will find A-list celebrities down to small girls wearing them.
tags:Coach Outlet|Coach Bags Factory Outlet|Coach Purses Outlet
Good information and, keep sharing like this.
ReplyDeleteCrm Software Development Company in Chennai