The script in this article was inspired by this one from Yaroslav Pentsarskyy, where he uses PowerShell to create a retention policy in SharePoint 2010. This works well for the built-in expiration actions (see http://msdn.microsoft.com/en-us/library/microsoft.office.recordsmanagement.policyfeatures.expiration_members.aspx), but I thought it was worth publishing a revised script for creating a retention policy to start a workflow as it requires a few extra properties in the policy XML.
The scenario for this script was that I wanted to create a retention policy on a specific content type associated with the Pages library on a number of sites. The workflow itself was associated directly to the Pages library and not to a site content type. The retention policy must start the workflow for each page, 20 days after it is created in the Pages library.
The workflow was created in SharePoint Designer and called “Review Page” - all it does is set a Status column to Expired. I then assigned the workflow to the “Content Page” content type on the Pages library of a site (see this article for details on how to do this in PowerShell) with the association name “Review Page Test”, as shown below:
We can now use PowerShell to create a retention policy to start this workflow for any page associated with the “Content Page” content type 20 days after it is created in the Pages library. Before the script can be run, you will need to load the following function in a PowerShell console with the SharePoint add-ins loaded:
function Update-IMPStartWorkflow($siteURL, $wfAssociationName, $listName, $contentType, $WfStartColumn)
{#Get web object
$web = Get-SPWeb $siteURL
write-host "Examining site:"$web.Title"at"$web.ServerRelativeUrl -ForegroundColor green
try
{
#Do the following if a list exists with the name specified by the user - e.g., Pages
if ($web.Lists[$ListName]) {write-host $web.Title"has a list called"$ListName -ForegroundColor green
#Get the list
$list = $web.Lists[$ListName]
#Create list policy if one does not exist already
#$policy = [Microsoft.Office.RecordsManagement.InformationPolicy.ListPolicySettings]($list)
#if (!$policy.ListHasPolicy)
#{
# $policy.UseListPolicy = $true
# $policy.Update()
#}
#Get the content type
$ct = $list.ContentTypes[$contentType]
#Get the Workflow template (parent association) ID from the association name
$wfAssociationId = $ct.WorkflowAssociations.GetAssociationByName($wfAssociationName, 1033).ParentAssociationId.ToString()
#Get the start column internal name and Id
$fieldId = $list.Fields[$WfStartColumn].Id.ToString()
$fieldName = $list.Fields[$WfStartColumn].InternalName
#Create a new policy
[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::CreatePolicy($ct, $null)
$newPolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($ct)
#Generate policy XML using the values required,
#injecting column and workflow details from the variables assigned above
$newPolicyFeatureXml = "<Schedules nextStageId=`"2`">"+
"<Schedule type=`"Default`">"+
"<stages>"+
"<data stageId=`"1`">"+
"<formula id=`"Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn`">"+
"<number>20</number>"+
"<property>"+$fieldName+"</property>"+
"<propertyId>"+$fieldId+"</propertyId>"+
"<period>days</period>"+
"</formula>"+
"<action type=`"workflow`" id=`""+$wfAssociationId+"`" />"+
"</data>"+
"</stages>"+
"</Schedule></Schedules>"
#Add retention policy
$newPolicy.Items.Add("Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration", $newPolicyFeatureXml)
write-host "Added retention policy to start workflow"$wfAssociation.Name"on content type"$ct.Name"for list"$list.Title"in site"$web.Title
}
else
{
#Report if the site does not have the list specified by the user
write-host $web.Title"does not have a list called"$listName -ForegroundColor red
}
}
catch
{
write-host "There has been an error:"$_ -ForegroundColor red
}
finally
{
#Dispose of the Web object
$web.Dispose()
}
}
Note that the important part of this script is where you generate the XML for the policy and assign it to the $newPolicyFeatureXml variable. This XML defines the properties required for setting the event, action and recurrence details.
If you need to set a recurrence on the policy, then you can add some extra properties to the "<data stageId=`"1`">"+ line. For example, to set a recurrence period of every 1 day, replace this line with the following XML:
"<data stageId=`"1`" recur=`"true`" offset=`"1`" unit=`"days`">"+
Once the function has been loaded, it can be called with the following command to create a retention policy for the “Content Page” content type, on the Pages library of the site http://portal, to start the workflow with the association name “Review Page Test”:
Update-IMPStartWorkflow -siteURL http://portal -wfAssociationName "Review Page Test" -listName "Pages" -contentType "Content Page" -WfStartColumn "Created"
The Information Management Policies administration page on the Pages library for the “Content Page” content type should now look as follows:
Another thing to note is how the workflow association ID is injected into the XML. An early draft of my script used the following line to get the workflow association ID:
$wfAssociationId = $ct.WorkflowAssociations.GetAssociationByName($wfAssociationName, 1033).Id.ToString()
However, running the script produced an “Invalid retention stage defined” error message in the Information Management Policies administration page against the retention policy:
To resolve this I needed to use the Parent Association ID (the workflow template) rather than the Association ID (the workflow instance), as follows:
$wfAssociationId = $ct.WorkflowAssociations.GetAssociationByName($wfAssociationName, 1033).ParentAssociationId.ToString()
I have added this information to the article in case you run into the same error message either in PowerShell or C# code and are looking for a solution…
Phil, I am trying to run your script, but I get the following error: There has been an error: You cannot call a method on a null-valued expression. Ideas? It finds the site and the library, but then throws the error.
ReplyDeleteHi,
ReplyDeleteI have same issue for OOTB SPD workflow.
I only have one action in SPD i.e send email , i also tried to set the description column some value. but it still says invalid retention stage defined.????
2015-12-7 xiaozhengm
ReplyDeletefitflops clearance
michael kors uk
tory burch outlet
oakley sunglasses
nike outlet
louis vuitton outlet
louis vuitton pas cher
kate spade outlet
gucci outlet
coach outlet
michael kors outlet
canada goose uk
coach factory outlet
christian louboutin shoes
nike blazer
jordan 8s
michael kors handbags
jordan 3 infrared
caoch outlet
true religion outlet
air jordan uk
michael kors
longchamp outlet
adidas shoes uk
coach factory outlet
coach factory outlet
nike blazers
ugg australia
nike uk
coach factory outlet
tiffany and co
basketball shoes
michael kors outlet uk
louboutin
air jordans
chaussure louboutin
air jordan 13
ugg outlet
louis vuitton outlet
Great Article..
ReplyDeleteOnline DotNet Training
.Net Online Training
Dot Net Training in Chennai
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
chaussure louboutin
ReplyDeleteair max 90 white
louis vuitton outlet online
yeezy boost 350 white
cheap jordan shoes
louis vuitton purse
skechers outlet
fitflops shoes
adidas pure boost black
louis vuitton bags
fitflops
true religion jeans
burberry outlet stores
discount oakley sunglasses
michael kors outlet
cheap ray bans
coach outlet online
louis vuitton outlet
ferragamo outlet
ray ban outlet store
michael kors outlet online
moncler uk
dolce and gabbana outlet online
pandora charms uk
nike store uk
ralph lauren uk
yeezy boost
michael kors handbags
reebok shoes
ed hardy
michael kors canada
louboutin pas cher
pandora jewelry outlet
cheap basketball shoes
longchamp handbags
20160721caiyan
louis vuitton outlet
ReplyDeletecoach outlet
kevin durant shoes 8
gucci outlet
louis vuitton
true religion jeans
louis vuitton uk
polo ralph lauren
louis vuitton
louis vuitton outlet stores
oakley sunglasses
coach outlet
ray ban sunglasses
coach outlet
kobe shoes 11
jordan retro 3
rolex submariner
mont blanc pens
michael kors outlet clearance
michael kors outlet online
michael kors outlet
toms shoes outlet
louis vuitton
michael kors outlet
michael kors outlet
toms shoes
louis vuitton handbags
mont blanc
christian louboutin outlet
michael kors outlet clearance
polo ralph lauren
polo ralph shirts
cheap jordans
longchamp handbags
tory burch outlet
jordan concords
cheap jordans
coach outlet online
coach canada
christian louboutin sale
20168.8wengdongdong
شركة تنظيف بالدمام
ReplyDeleteشركة تنظيف منازل بالدمام
شركة تنظيف فلل بادمام
شركة تنظيف شقق بالدمام
-----------------------------------------
شركة كشف تسربات المياه بالقصيم
شركة كشف تسربات المياه بعنيزة
كشف تسربات المياه ببريدة
كشف تسربات المياه بالقصيم
كشف تسربات المياه بعنيزة
ray ban sunglasses
ReplyDeletechristian louboutin paris
oakley sunglasses
louis vuitton outlet
celtics jerseys
louis vuitton outlet
louis vuitton outlet
kate spade handbags
prada outlet
michael kors
20173.9chenjinyan
nike air max
ReplyDeletereebok classics
converse outlet
vans store
michael kors outlet online
vans for sale
longchamp handbags
jordan shoes
mac cosmetics outlet
coach outlet store online clearances
2017.5.15chenlixiang
The article you have shared here very good. This is really interesting information for me. Thanks for sharing!
ReplyDeletehotmail login |hotmail sign in |free hotmail login
شركة تنظيف منازل بالجبيل
ReplyDeleteشركة مكافحة حشرات براس تنورة
ReplyDeleteشركة فحص فلل بالرياض
البيت السعيد
شركة فحص فلل، أعمال الفحص للفلل الجديدة والقديمة من خلال مهندسين خبرة في مجال الفحص و الترميم من شركة البيت السعيد شركة فحص فلل بالرياض ، من خلال أدوات وأجهزة تكشف عن ما يحتاج إلى التعديل بمختلف أركان المكان، شركتنا متخصصة في الفحص لجميع المباني السكنية وغيرها، وتقوم بتحديد التكلفة النهائية للمبنى المراد اقتنائه بعد مباشرة عملية الفحص لذا شركة البيت السعيد شركة فحص فلل بالرياض ثقه لا تقارن
فحص فلل بالرياض
البيت السعيد
للاستفسار عن جميع خدمات البيت السعيد عزل مائي و عزل حراري و عزل اسطح و عزل خزانات و عزل فوم وجميع انواع العوازل و رش مبيد و مكافحة حشرات و تسليك مجاري و شركة كشف تسربات المياه و فحص فللو صيانة مباني و ترميم منازل و نقل عفش و اثاث بالرياض يرجي الاتصال على 0543578920
او زورو موقعنا على الانترنت
http://www.elbaytelsaeed.com/2017/09/14/water-leak-detection-company-riyadh/
You should come here to learn more and more.............
ReplyDeleteEaseUS Partition Master 12.8 Key
EaseUS Partition Master PRO 12.5 Crack & Serial Key Download is the disk that is comprehensive is the permanent unit and system optimization pc software for Windows-based administration without data loss or any risk.
LOVELY , LOVELY AND LOVELY........
ReplyDeleteCOREL DRAW X8 Keygen + Crack
Corel Draw x8 Keygen is truly well known and worlds most excellent graphics software. Corel Draw x8 Keygen can create your pictures amazingly with greatest editing tools and latest supportive stuff.
Avast Internet Security License Key
ReplyDeleteAvast Internet Security has always been at the top of providing protection to your systems for a long time. Their latest version of security named as Avast Internet Security is a robust security suite that consists numerous tools to protect your system.
ReplyDeleteنقل اثاث من الرياض الى الكويت 0507716412
شركة شحن عفش من الرياض الى الكويت
نقل اثاث من الرياض الى الاردن 0507716412
شركة شحن عفش من الرياض الى الاردن
شركة نقل اثاث من الرياض الى الدمام
شركة نقل عفش من الرياض الى الدمام
نقل اثاث من الرياض الى الامارات 0507716412
شركة شحن عفش من الرياض الى الامارات
نقل اثاث بالمدينة المنورة
نقل عفش في المدينة المنورة
The article was very interesting to read, thank you for sharing the information
ReplyDeleteObat Untuk Panas Di Lambung
Obat Keropos Tulang Tradisional
Obat Telinga Berdenging
Obat Luka Pada Dinding Lambung
Cara Menghentikan Pertumbuhan Tumor
Cara Sembuhkan Bengkak Di Leher
This comment has been removed by the author.
ReplyDeleteThank you for your support who has read our article. I'm very happy if you can share our article below
ReplyDeleteToko Obat Herbal
Cara Mengatasi Nyeri Sendi
Obat Penyakit Jantung
Cara menambah HB darah
Cara Mengobati Milia
1、
ReplyDeletecheap jordan shoes
golden goose sneakers
golden goose
fitflops clearance
coach outlet
basketball shoes
cheap jordans
reebok outlet store
cheap basketball shoes
cheap air jordans
20180601xiaoke
ReplyDeleteuggs on sale
cheap air jordans
christian louboutin
cheap ray bans
isabel marant outlet
bulgari jewelry
kyrie 4
fitflops shoes
nike outlet online
kate spade outlet online
Simply submission the best place a bet, You are investing buy specific commodity from the owner if you're the irresistible prospective buyer. You read and admit the world shipping charges application t's and c's starts in brand name new time frame or it may be bill. Scan premiums previous quotes unquestionably is short sale change within the event you acceleration you the greatest put money on sum..
ReplyDelete3. Der Verkufer kann Angebote i have to dfb trikot müller be Auktionsformat zustzlich amazon müller trikot durch einer Sofort Kaufen Funktion versehen. Diese kann von einem Kufer ausgebt werden, Solange noch kein Gebot auf family room Artikel abgegeben Coach Outlet Online Store oder ein Mindestpreis maillot de foot personnalise noch nicht erreicht wurde.
This amazing sum of Maglie Poco Prezzo money comes along with topical practices works, Place a burden on, Broker and also other extra charges. The item money manuel neuer trikot rot is juegos de futbol susceptible to change before make expenses. The local surf maillot foot 2018 forecast in an western european subscriber Maglie Calcio Poco Prezzo express anyway us, Transfer cask on this subject select Maillot De Foot Pas Cher certainly not recoverable.
maillot de foot pas cher
ReplyDeletemaillot paris 2018
maillot de foot pas cher
Maillot Foot Pas Cher
maillot foot pas cher
maillot psg pas cher
maillot de foot pas cher
louboutin pas cher
louboutin soldes
When running any site, you need to do all that you can secure it. To begin securing your WordPress site, you should first make a reinforcement of your WordPress database and your fundamental website backup records (transfers, modules, subjects, and so forth.).
ReplyDeleteThanks for sharing the information
ReplyDeleteKhasiat QnC Jelly Gamat
Obat Eksim Atopik
Pengobatan Herbal Penyakit Liver
Cara Mengobati Alergi Dingin
Obat Paling Mujarab untuk Diabetes
Obat Batu Empedu Alami
PENGOBATAN PENYAKIT AMANDEL
Thank you very much because you have always shared many new things to us
ReplyDeleteI am very happy because I can get articles that are very weighty contents
Maybe I will come back to your site. Greetings :)
Obat Encok Obat Sesak Nafas Obat Batu Kandung Kemih Obat Penghilang Jerawat Obat Gastritis Obat Sakit Lutut Cara Menghilangkan Jerawat Bruntusan Cara Menyembuhkan Kaki Pecah-Pecah Obat Batuk Rejan Cara Menghilangkan Nyeri Haid
A steam cleaning company in Jeddah
ReplyDeleteAn insect control company in Riyadh
Landscaping in Riyadh
Landscaping Company in Riyadh
Pest Control in Riyadh
Transportation of furniture in Medina
Detection of leaks in Riyadh
También puede visitar una tienda de ladrillo y mortero de Michael Kors o su sitio web y comprar directamente un bolso Michael Kors desde allí. Usar un bolso de Michael Kors les permite a los demás reconocer que el habitante urbano educado toma la moda realmente con seriedad. Los bolsos de hombro son particularmente refinados y elegantes.
ReplyDelete{Bolsas Michael Kors Precios | Bolsos Michael Kors Outlet | Michael Kors Rebajas}
En vacker konstnärlig skapelse av vävt läder, som ger ett skalskaligt utseende - liknar en snakeskin eller fiskhud, linjer utsidan av påsen. Läderens bältros är små läderringar. Det finns också gyllene accenter på väskan. Slutresultatet är svagt liknar kedjepost.
{Michael Kors Rea | Michael Kors Väska Rea | Michael Kors Plånbok}
شركة مكافحة النمل الابيض
ReplyDeleteشركة مكافحة حشرات
شركة رش مبيدات
maillot foot pas cher
ReplyDeletemaillot pas cher
maillot psg pas cher
maillot equipe de france pas cher
maillot de foot pas cher 2018
ensemble de foot pas cher
maillot de foot pas cher
ensemble de foot pas cher
maillot de foot pas cher
maillot foot pas cher
maillot pas cher
maillot psg pas cher
maillot equipe de france pas cher
maillot de foot pas cher 2018
maillot equipe de france pas cher
maillot de foot pas cher 2018
ensemble de foot pas cher
maillot de foot pas cher
maillot foot pas cher
maillot pas cher
maillot psg pas cher
camisetas de futbol
ReplyDeletecamisetas de futbol baratas
camisetas futbol baratas
camiseta real madrid barata
equipaciones de futbol baratas
comprar camisetas de futbol
camisetas de futbol baratas 2017
comprar camisetas de futbol
tiendas de futbol
camisetas de futbol
camisetas futbol baratas
camisetas futbol
camiseta real madrid barata
bounty camisetas futbol
camisetas de futbol 2018
maglie calcio a poco prezzo
ReplyDeletemaglie calcio poco prezzo
maglie calcio 2018
maglie italia
maglie calcio a poco prezzo
maglie calcio poco prezzo
maglie calcio 2018
maglie italia
maglie calcio a poco prezzo
maglie calcio poco prezzo
maglie calcio 2018
maglie italia
maglie calcio a poco prezzo
maglie calcio poco prezzo
maglie calcio 2018
maglie italia
maglie calcio a poco prezzo 2018
maglie calcio poco prezzo 2018
camisetas de futbol
ReplyDeletecamisetas de futbol baratas
camisetas futbol baratas
camiseta real madrid barata
equipaciones de futbol baratas
comprar camisetas de futbol
camisetas de futbol baratas 2017
comprar camisetas de futbol
tiendas de futbol
camisetas de futbol
camisetas futbol baratas
camisetas futbol
camiseta real madrid barata
bounty camisetas futbol
camisetas de futbol 2018
When you were injured when you were upset, I would take care of you and sleep
ReplyDeleteObat Bisul Alami
Obat Kanker Darah Alami
Cara Mengatasi Sembelit Pada Ibu Hamil
Obat Usus Buntu Alami
Mengobati Kaligata Pada Ibu Hamil
Herbal Solusi Sehat
diagnostic structure
ReplyDeletebureau d'etude structure paris
VRD
Agence Marketing Digital
entreprise generale de batiment idf
ReplyDeleteEntreprise de platrerie Paris
bureau d'etude infrastructure
construction de fondation paris
bureau d'etude pluridisciplinaire
bureau d'etude mur porteur
bureau d'etude electricite paris
ReplyDeleteentreprise genie climatique
renovation appartement paris
bureau d'étude structure prix
entreprise ouverture mur porteur
which is required in this place and is integrated in the provision of this service, insects are a nuisance to all,شركة مكافحة حشرات بمكة
ReplyDeleteشركة رش مبيدات بمكة
افضل شركة مكافحة حشرات
شركة رش مبيدات بالمجمعة
A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
ReplyDeleteThere are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
Coach Store Near Me trends come and go, but a Coach stands the test of time.
The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
All Michael Kors Outlet Online Store have serial numbers.