PowerShell & SharePoint: Using New-WebServiceProxy to Post New Completed Tasks Automatically

Recently, I was asked to help automate a friend’s super boring daily duty of logging repetitive activities to a SharePoint Task list. Even though I’m no longer regularly working with SharePoint (yay!), I accepted the challenge.

Below is the script I created, which can be scheduled (and mixed up, even using $a = Get-Random -minimum 15 -maximum 1250; Start-Sleep -s $a within the function) to fill in the form and post new completed Tasks automatically.

Here are a few interesting things while creating this script:

  • Invoke-WebRequest is not the appropriate cmdlet for this task. SharePoint’s form field naming scheme was complex and ultimately, Invoke-WebRequest was unable to successfully submit the task. It seemed like it worked, but the new items never appeared.
  • New-WebServiceProxy works with 2007, 2010 and SharePoint 2013 (as well as PowerShell 2.0 and 3.0) but beware xml’s case sensitivity.
  • Lists.UpdateListItems is used to add new tasks, not just update tasks
  • Fields with spaces or renamed columns could present issues. Makes sure you use the FieldInternalName for the column name. This can be found in the source code of the New page.
  • A people/group picker field only requires the user id of the user in SharePoint. You can get this ID by deciphering the user’s URL or just use ResolvePrincipals as seen in this script. The format should look like this: <Field Name=’AssignedTo’>32</Field>
  • Dates require this format: YYYY-MM-DD
  • The default Description field is actually called the Body field and must be referenced as such.
  • Lookup fields work, but the code below doesn’t automatically resolve the lookup fields. I just went get the ID (by looking at the URL of the item) and manually input it.

Special thanks goes out to the PowerShell team for the jump start.

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in PowerShell, SharePoint
2 comments on “PowerShell & SharePoint: Using New-WebServiceProxy to Post New Completed Tasks Automatically
  1. dicconb says:

    Thanks very much for this, has saved me a good few hours :)

  2. Garek says:

    Thanks for this information …

    Question, Can this method be used to post a document to a document library? I’m having trouble finding any examples of a document post.

    Thanks,

    ken

Leave a Reply

Your email address will not be published. Required fields are marked *

*