Its pretty easy to add list items to SharePoint with Powershell so here's a quick sample
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Add an new item to the announcements list
$site = new-object Microsoft.SharePoint.SPSite("http://teams.contoso.com")
$web = $site.rootweb
$list = $web.Lists["Announcements"]
$newitem= $list.items.Add()
$newitem["Title"]= "New CFO Appointed";
$newitem["Body"]= "Our new CFO is Harry Varden, money still not recovered from previous appointee, legal action is ongoing";
$newitem["Expires"]= [DateTime]::Now.AddDays(5)
$newitem.update()
$web.Dispose()
$site.Dispose()
This could easily be turned into a function
Here I've referenced the field names by text but I could have used SharePoint's built-in list of field Id's using the SPBuiltInFieldId class.
In that case the fields are referenced by using the syntax [Microsoft.SharePoint.SPBuiltInFieldId]::Title
To get a list of fields in the class you can use this PowerShell command
[Microsoft.SharePoint.SPBuiltInFieldId] | get-member -static | select name | more
get-member is a handy class that reflects over a given object and returns the list of properties, fields and methods.
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Colin Byrne
E-mail