将x年以上的项目从一个列表移动到另一个列表 [英] Move items older than x years from one list to other list

查看:54
本文介绍了将x年以上的项目从一个列表移动到另一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我进行了实验室模拟,尝试使用Power Shell根据创建日期将3个项目从列表复制到其他列表.该代码成功执行,但显然当我检查到目的地列表时,该项目不存在.这是代码:

Hello Guys, i made lab simulation, trying to copy 3 items from a list to other list based on created date using power shell. The code executed successfully, but apparently when i checked to the destination list, the item is not there. Here's the code:

[void] [System.reflection.Assembly] :: LoadWithPartialName("Microsoft.SharePoint")
$ site =新对象Microsoft.SharePoint.SPSite("http://sp2013/sites/MMS") 
$ web = $ site.rootweb 
$ list = $ web.Lists ["Tes"]
$ dest = $ web.lists ["Backup_Test"]
$ caml ='< Where>
        < Leq>
            < FieldRef Name =已创建" />
            < Value IncludeTimeValue =" TRUE"类型="DateTime"> 2017-12-12T01:00:00Z</Value>
        </Leq>
    </在哪里>'
$ query =新对象Microsoft.SharePoint.SPQuery 
$ query.Query = $ caml |写输出
$ items = $ list.GetItems($ query) 
$ listItemsTotal = $ items.Count;
for($ x = $ listItemsTotal-1; $ x -ge 0; $ x--)
            {
                          $ dest.AddItem()= $ items [$ x];
 写宿主项目:$ items [$ x]
            }
$ web.Dispose() 
$ site.Dispose()

[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = new-object Microsoft.SharePoint.SPSite("http://sp2013/sites/MMS") 
$web = $site.rootweb 
$list = $web.Lists["Tes"]
$dest = $web.lists["Backup_Test"]
$caml='<Where>
        <Leq>
            <FieldRef Name="Created" />
            <Value IncludeTimeValue="TRUE" Type="DateTime">2017-12-12T01:00:00Z</Value>
        </Leq>
    </Where>'
$query=new-object Microsoft.SharePoint.SPQuery 
$query.Query=$caml | Write-Output
$items=$list.GetItems($query) 
$listItemsTotal = $items.Count;
for($x=$listItemsTotal-1;$x -ge 0; $x--)
            {
                          $dest.AddItem() = $items[$x];
 write-host item : $items[$x]
            }
$web.Dispose() 
$site.Dispose()


上述写入主机项的输出(抱歉,无法在此处放图片):

Output from write-host item above (sorry cant put pic here):


我尝试将某些部分更改为:

I've tried change some part to:

foreach($ list.Fields中的$ spField)

            {
                          $ newSPListItem = $ items;

foreach($spField in $list.Fields)

            {
                          $newSPListItem = $items;

写主机ini:$ newsplistitem;

write-host ini : $newsplistitem;

            }

            }

成功执行,输出类似,但列表中没有变化.

Executed Successfully with similar output, but no change in the list.

有人帮忙吗?谢谢!

推荐答案

嗨伊万德,

请改用以下链接中的演示脚本:

最好的问候


这篇关于将x年以上的项目从一个列表移动到另一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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