使用PowerShell更新列表中的所有项目 [英] Update all items in a list using PowerShell

查看:75
本文介绍了使用PowerShell更新列表中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含约500个项目的SharePoint 2010列表.我需要创建一个PowerShell脚本,该脚本将调用所有这些列表项,然后为每个项目更新特定的列(我们将其称为数字").

I have a SharePoint 2010 list with around 500 items. I need to create a PowerShell script that will call ALL of these list items, and then update a specific column (we'll call it 'Number') for EACH item.

每个项目需要更新的列(数字)是数字"列.我只需要在每个列表项中插入一个随机数,范围是0-100.重复的数字无关紧要,但是需要随机选择.

The column (Number) that needs to be updated for each item is a Number column. I simply need to insert a random number into each list item, ranging from 0-100. It doesn't matter if numbers are repeated, but they need to be chosen at random.

我对PowerShell还是很陌生,但仍在尝试了解基础知识.如果有人可以为我提供有关如何配置此cmdlet的帮助,将不胜感激!

I am very new to PowerShell and am still trying to understand the fundamentals. If someone could provide me with assistance around how to configure this cmdlet, that would be greatly appreciated!

非常感谢!

-乔什

推荐答案

假定要更新的列表位于 http://YouServer/ListLocation/Lists/TheList :

Assuming the list you want to update is located at http://YouServer/ListLocation/Lists/TheList:

$web = Get-SPWeb http://YourServer/ListLocation
$list = $web.Lists["TheList"]

foreach ($item in $list.Items)
{
  $item["Number"] = Get-Random -Min 0 -Max 100;
  $item.Update();
}

您需要在 SharePoint 2010命令行管理程序中执行以下代码,或手动添加SharePoint PowerShell管理单元:

You need to execute this code in the SharePoint 2010 Management Shell or add the SharePoint PowerShell snap-in manually:

Add-PSSnapin Microsoft.SharePoint.PowerShell

这篇关于使用PowerShell更新列表中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆