SharePoint PowerShell Script Use List,Add Field To List ,Create Discussion

//得到List

$web = get-spweb(http://dexter-pc:90s);

$CustomerList = $web.Lists["Customer"];

//给List添加字段

$CustomerList.Fields.Add("Customer_Name","Text","false");

$CustomerList.update();

 

//给List 添加Item

$CustomerItem = $CustomerList.AddItem();

$CustomerItem["Customer_Id"] = "10000";

$CustomerItem["Customer_Name"]="Name";

$CustomerItem.Update();

//得到Item id

$CustomerItemId = $CustomerItem.ID;

 

$DeviceList = $web.Lists["Device"];

$DeviceListItem = $DeviceList.AddItem();

//添加Lookup类型字段

$DeviceListItem["Device_Customer_Id"] = New-Object Microsoft.SharePoint.SPFieldLookupValue($CustomerItemId,"10001");

 

 

 

//Script Create Discussion,Ticket 是一个讨论版

$ticketList = $web.Lists["Ticket"];

$ticketItem = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($ticketList,"Discussion Name");

$ticketItem["Country_Code"] = "USA";

 

//在PowerShell Script 中 转义字符有`n 表示换行,"" 双重双引号转义位双引号。

$ticketItem["Description"]  = "All users affected: NO`n
Users affected: SOME RADIOLOGISTS`n
Can users perform work: ""INCONVENIENT""`n
Patients affected: YES, SOME`n"

//给user类型的字段添加值

$ticketItem["Owner_User"] = $web.AllUsers["Domain\Name"];

//给时间类型字段赋值

$ticketItem["Created_Time"] = "2011-01-01 14:00:00";

 //最后更新

$ticketItem.update();

 

你可能感兴趣的:(SharePoint)