3

如何使用 PowerShell 修改 SharePoint 列表中的项目值?当我尝试以下操作时:

$splist.GetItems() | ForEach-Object{
 #Write-Host $_["Item"]

 if($_["Item"] -eq $null){
  $SPFileCollection = $folder.Files
  $upFile=Get-ChildItem D:\Tools\SP-scripts\MDNSO-template.aspx
  $tmpValue = $_["Title"]
  $filename = "EM_Doc_Library\$tmpValue"
  $SPFileCollection.Add("EM_Doc_Library\$tmpValue",$upFile.OpenRead(),$false)
  Write-Host "creating the file"
  Write-Host $_["Title"]
  $_["Item"] = "MDNSO-<$tmpValue>"
 }
}

它说,unable to index into an object of type SPlistItem.

4

2 回答 2

9

以下是您可以尝试执行的操作的摘要:

$spWeb = Get-SPWeb -Identity http://yourdomain/sites/config
$spList = $spWeb.Lists["AppSettings"]
$spItem = $spList.GetItemById(10013) //or another way that you prefer.
$spItem["Name"] = "MyName"
$spItem.Update()

有关更多信息,您应该查看此博客文章。它包含如何使用 PowerShell 添加、更新和删除列表项的示例:http: //mysharepointwork.blogspot.no/2010/09/addupdatedelete-list-items-using.html

于 2012-06-21T08:54:31.373 回答
0

使用 powershell,我使用来自 social.msdn.microsoft.com/Forums的脚本非常完美地完成了它

这是示例代码,一旦出现提示,请键入“YES”继续。并替换唯一的两个变量: (urlToTheYourSite & YourListNameToDelete)

write-host "This will delete data, type YES to continue"
$retval = read-host 
if ($retval -ne "YES") 
{
    write-host "exiting - you did not type yes" -foregroundcolor green
    exit
}
write-host "continuing"

$web = get-spweb https://urlToTheYourSite
$list = $web.lists | where {$_.title -eq "YourListNameToDelete"}
Write-host "List $($list.title) has $($list.items.count) entries"
$items = $list.items

foreach ($item in $items)

{
    Write-host "  Say Goodbye to $($item.id)" -foregroundcolor red

    $list.getitembyid($Item.id).Delete()
}
于 2017-11-30T07:17:24.750 回答