Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
$sourceWebURL = "http://srcurl"
$sourceListName = "Source"
$destinationWebURL = "http://desurl"
$destinationListName = "Destination"
$spSourceWeb = Get-SPWeb $sourceWebURL
$spDestinationWeb = Get-SPWeb $destinationWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spDestinationList = $spDestinationWeb.Lists[$destinationListName]
$RootFolder = $spDestinationList.RootFolder
$spSourceItems = $spSourceList.Items
ForEach ($item in $spSourceItems)
{
Try
{
$binary = $item.File.OpenBinary();
if ($binary -ne $null)
{
$sBytes = $item.File.OpenBinary()
[Microsoft.SharePoint.SPFile]$spFile = $RootFolder.Files.Add($item.Name, $sBytes, $true)
$theItem = $spFile.Item
write-host -f Green "...Success!"
$pos = $item["Author"].IndexOf("#")
$userAuthorLogin = "domainname\"+$item["Author"].Substring($pos+1)
$pos1 = $item["Editor"].IndexOf("#")
$userEditorLogin = "domainname\"+$item["Editor"].Substring($pos+1)
$dateCreatedToStore = Get-Date $item["Created"]
$dateModifiedToStore = Get-Date $item["Modified"]
$userAuthor = Get-SPUser -Web $spDestinationWeb | ? {$_.userlogin -eq $userAuthorLogin}
$userAuthorString = "{0};#{1}" -f $userAuthor.ID, $userAuthor.UserLogin.Tostring()
$userEditor = Get-SPUser -Web $spDestinationWeb | ? {$_.userlogin -eq $userEditorLogin}
$userEditorString = "{0};#{1}" -f $userEditor.ID, $userEditor.UserLogin.Tostring()
#Sets the created by field
$theItem["Author"] = $userAuthorString
$theItem["Created"] = $dateCreatedToStore
#Set the modified by values
$theItem["Editor"] = $userEditorString
$theItem["Modified"] = $dateModifiedToStore
#Store changes without overwriting the existing Modified details.
$theItem.UpdateOverwriteVersion()
write-host -f Green "...Success!"
}
}
Catch [system.exception]
{
write-host "Caught a system exception for " $item.ID $item.Title
}
Finally
{
$spSourceWeb.Dispose();
$spDestinationWeb.Dispose();
}
}
Read Next
Migrate data from CSV to SharePoint List - PowerShell
Set Permission to List Items using PowerShell
Tags
AAD
AI
API
ARM
ASPM
AWS
AWS Comprehend
AWS Secrets Manager
Actions
Amazon Bedrock
Angular
Ansible
Automation
Azure
Azure CLI
BDC
Bash
Bible API
Bitbucket
Bot
CI/CD
CLI for Microsoft 365
CSOM
Citrix
Cloud
Cloud Computing
Cloud Watch
CloudWatch
CodeWhisperer
Computer Vision API
Copilot
Data Extraction
DefectDojo
DevOps
DevSecOps
Docker
Docker Scout
Dotnet
EKS
Elastic Transcoder
EventBridge
External Secrets Operator
Faith
GCP
GenAI
Generative AI
GitHub
GitLab
GitLeaks
GitOps
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
Identity
InfoPath
Integration
Istio
JQuery
JavaScript
Jenkins
Jinja2
Kiali
Kubernetes
LUIS
Lambda
LangChain
Linode
Linux
Lotus Notes
Machine Learning
Manage Secrets
Microservices
Microsoft 365
Microsoft Power Platform
Microsoft Teams
Migration
Milvus
NJSScan
Nintex
OIDC
Office Store
Ollama
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Pod
Postman
Power Apps
Power Automate
PowerApps
PowerShell
Python
REST
Redis
Roles
S3
SNS
SPFX
SQL Server
SSL
SSRS
Security
Semantic Search
Semgrep
Serverless
Service Mesh
ServiceNow
SharePoint
Slack
TFS
Teams
Terraform
VM
Vault
Vector Database
Vulnerability
Windows
Windows Server
YAML
Yammer
tfsec