惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
Scott Helme
Scott Helme
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
C
Cyber Attacks, Cyber Crime and Cyber Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
I
Intezer
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
V2EX - 技术
V2EX - 技术
Google Online Security Blog
Google Online Security Blog
L
Lohrmann on Cybersecurity
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LINUX DO - 热门话题
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Latest news
Latest news
B
Blog
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
L
LangChain Blog
GbyAI
GbyAI
Last Week in AI
Last Week in AI
S
Security Affairs
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
Security Latest
Security Latest
Vercel News
Vercel News
Y
Y Combinator Blog
G
GRAHAM CLULEY
S
Securelist
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
雷峰网
雷峰网

博客园 - Sunmoonfire

SharePoint 2013无代码实现列表视图的时间段动态筛选 SharePoint 2013:自定义ECB菜单项的添加 SharePoint Foundation 2013 with SP1 在SharePoint列表中使用自增栏 SharePoint 2010自定义母版页小技巧——JavaScript和CSS引用 修改SharePoint列表项显示“新”图标的天数 在SharePoint 2010页面中嵌入SWF文件 在LINQ to SharePoint中使用创建时间,创建者,修改时间,修改者 SharePoint 2010之LINQ与SPMetal 修改SharePoint页面上的控件数量的限制 SharePoint 2010:部署.resx(资源)文件到App_GlobalResources的简单方法 在SharePoint 2010中使用jQuery 在SharePoint 2010环境下区分w3wp进程 打SharePoint 2010 SP1后访问用户配置文件同步服务应用程序出错的解决办法 使用[本人]创建视图筛选时的一个问题和解答 "缺少服务器端相关性"的内容定位 SharePoint 2010开发工具图解系列:Visual Studio 2010创建事件接收器 SharePoint 2010开发工具图解系列:Visual Studio 2010创建列表 SharePoint 2010开发工具图解系列:Visual Studio 2010 SharePoint Tool入门
通过PowerShell实现SharePoint列表增删改
Sunmoonfire · 2012-08-13 · via 博客园 - Sunmoonfire

通过 powershell 脚本实现 SharePoint 2010 列表项添加删除修改的例子。

添加列表项

$spAssignment = Start-SPAssignment
$mylist = (Get-SPWeb -identity http://SP -AssignmentCollection $spAssignment).Lists["listName"]
$newItem = $mylist.Items.Add()
$newItem["Title"] = “通过Powershell添加”
$newItem["description"] = “PowerShell 魔法”
$newItem.Update()
Stop-SPAssignment $spAssignment

更新列表项

$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb http://SP -AssignmentCollection $spAssignment

接下来是获取列表:

$SPList = $SPWeb.Lists["Announcements"]

当我们获取到列表后,就可以进一步获取列表项了。最直接的办法是调用 GetItemByID() 方法:

$SPItem = $SPList.GetItemById("1")

上面的例子需要我们知道列表项的ID。如果我们并不知道列表项ID,也可以使用 Where-Object 命令来替代:

$SPItem = $SPList.Items | Where { $_["Title"] -eq "New Announcement" }

当我们获取到列表项以后,就可以修改其内容了。

$SPItem[“Title”] = "我的标题"
$SPItem[“Body”] = "我的内容"

修改好该列表项后,还必须调用 Update() 方法来提交修改。

所以事情都完成后,通过 Stop-SPAssignment 命令来释放 SPWeb 对象。

Stop-SPAssignment $SPAssignment

删除列表项

下面的例子将对列表项进行遍历,读取列表项的名称,判断如果包含字符串“3”,则将其删除。

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = new-object Microsoft.SharePoint.SPSite("http://SP")
$relweburl = '/Docs"
$web = $site.openweb($relweburl)
$list=$web.Lists["testList"]
$listItems = $list.Items
$listItemsTotal = $listItems.Count

for ($x=$listItemsTotal-1;$x -ge 0; $x--)
{
if($listItems[$x].name.Contains("3"))
{
Write-Host("DELETED: " + $listItems[$x].name)
$listItems[$x].Delete()
}
} 

参考资料

Add,Update,Delete List items using powershell sharepoint 2010