locked
Is is possible to export or Migrate only a portion of a list RRS feed

  • Question

  • So here is my situation,  we have a subsite that wants to move some content out of its site to another site collection.

    They have a calendar in that subsite they want to move.  They asked if I could move only the last 2 months of items and not any of the really old stuff. 

    Is this possible?


    pfcjt@hotmail.com

    Friday, December 21, 2018 11:02 PM

Answers

  • Hi,

    Yes you can move based on the List items based on the date range. 

    Please use the below power shell if you are not using any other migration tool

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    
    $outputPath = "d:scriptscheckedfiles.csv"
    
    $dateFrom = [datetime]("1/22/2016")
    $dateTo = [datetime]("3/5/2016")
    
    $siteURL = "http://somesite"
    $site = Get-SPSite($siteURL)
    
    Add-Content -Path $outputPath -Value "WebUrl|ListTitle|ListBaseType|ItemName|ItemUrl|ItemModified"
    
    foreach($web in $site.AllWebs) 
    {
      foreach($list in $web.Lists) 
      {
    
          if ($list.Title -ne "Workflows" -and $list.Title -ne "Workflow History" -and $list.Title -ne "User Information List")
           {
          foreach ($listItem in $list.Items)
           {
    
              $a=[datetime]($listItem["Modified"])
    
    
    	   $datefromAsString = Get-Date $dateFrom -format d
    	   $dateToAsString = Get-Date $dateTo -format d
               $modifiedAsString=Get-Date $a -format d
    
               Write-Host "from:" $dateFromAsString " to:" $datetoAsString " item:" $modifiedasString
    
    	  if (($a -gt $dateFrom) -and ($a -le $dateTo))
    	   {
    	       $text = $web.Url + "|" + $list.Title + "|" + $list.BaseType + "|" + $listItem["Title"] + "|" + $listItem.Url + "|" + $modifiedAsString 
    
                   Add-Content -Path $outputPath -Value $text
    
                   Write-Host "Item found between dates and is added to csv file" 
              }
           }
         }
    
      }
    
      $web.Dispose();
    }
    
    $site.Dispose();
    
    <footer style="box-sizing:border-box;clear:both;font-size:14px;">
    </footer>

    Hope this helps...

    ---------------------------------------------------------------------------------------------------------

    Please don't forget to “mark the replies as answers if they helped, also set "like" it’s a boost for us to keep blogging J

    Friday, December 21, 2018 11:11 PM

All replies

  • Hi,

    Yes you can move based on the List items based on the date range. 

    Please use the below power shell if you are not using any other migration tool

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    
    $outputPath = "d:scriptscheckedfiles.csv"
    
    $dateFrom = [datetime]("1/22/2016")
    $dateTo = [datetime]("3/5/2016")
    
    $siteURL = "http://somesite"
    $site = Get-SPSite($siteURL)
    
    Add-Content -Path $outputPath -Value "WebUrl|ListTitle|ListBaseType|ItemName|ItemUrl|ItemModified"
    
    foreach($web in $site.AllWebs) 
    {
      foreach($list in $web.Lists) 
      {
    
          if ($list.Title -ne "Workflows" -and $list.Title -ne "Workflow History" -and $list.Title -ne "User Information List")
           {
          foreach ($listItem in $list.Items)
           {
    
              $a=[datetime]($listItem["Modified"])
    
    
    	   $datefromAsString = Get-Date $dateFrom -format d
    	   $dateToAsString = Get-Date $dateTo -format d
               $modifiedAsString=Get-Date $a -format d
    
               Write-Host "from:" $dateFromAsString " to:" $datetoAsString " item:" $modifiedasString
    
    	  if (($a -gt $dateFrom) -and ($a -le $dateTo))
    	   {
    	       $text = $web.Url + "|" + $list.Title + "|" + $list.BaseType + "|" + $listItem["Title"] + "|" + $listItem.Url + "|" + $modifiedAsString 
    
                   Add-Content -Path $outputPath -Value $text
    
                   Write-Host "Item found between dates and is added to csv file" 
              }
           }
         }
    
      }
    
      $web.Dispose();
    }
    
    $site.Dispose();
    
    <footer style="box-sizing:border-box;clear:both;font-size:14px;">
    </footer>

    Hope this helps...

    ---------------------------------------------------------------------------------------------------------

    Please don't forget to “mark the replies as answers if they helped, also set "like" it’s a boost for us to keep blogging J

    Friday, December 21, 2018 11:11 PM
  • That is interesting.  I like it!   I have a couple questions about the content exported.  Looking at your code,  I am not sure all columns would be included.   Most lists we have have at least 10 columns of information. 

    Then there is how would i import that into the other site?


    pfcjt@hotmail.com

    Monday, December 24, 2018 1:25 AM
  • This Script will update/Import the list items to a new site from the .csv file 

    $SiteUrl = "http://otherSPsite"
    $web = Get-SPWeb $SiteUrl
    $ListName = "your List"
    $List = $web.Lists[$ListName]
    
    $csv = import-csv "c:\updateddata.csv"
    
    foreach($item in $csv)
    {
        $spItems = $List.GetItemById($item.ID)
        write-host $item.Region
        write-host $item.Phone Number
        write-host $spItems.Region Name
    
        #$spItems["Region Name"] = $item.Region
        #$spItems["Phone Number"] = $item.Phone Number
        #$spItems.SystemUpdate()
    }
    
    $web.Dispose()

     Hope this helps...

    ---------------------------------------------------------------------------------------------------------

    Please don't forget to “mark the replies as answers if they helped, also set "like" it’s a boost for us to keep blogging J

    Monday, December 24, 2018 1:37 AM
  • Hi Chilly,

    First, move calendar list to Different SharePoint Site. 

    Move a List or Calendar to a Different SharePoint Site for your reference:

    https://saniac.com/move-a-list-or-calendar-to-a-different-sharepoint-site/

    Second,  create a standard view with a filter like Created is greater than [Today]-60 in the new site, switch to the newly created view, choose all items, delete items. 



    Best Regards, 

    Lisa Chen 



    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, December 24, 2018 9:34 AM
  • Hi Chilly,

    If a reply helps you, please remember to mark it as an answer, it will be beneficial to others in the community who meet this similar issue in the future. 

    Thanks,

    Lisa Chen

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, December 27, 2018 9:17 AM