I'm using Export-SPWeb to export list from one Sharepoint site collection and Import-SPWeb to import this list to another site collection.
I need to do it regularly and that the list and all data in it would be overwritten every time.
Now the list is always updated - items are appended to the list so the same data repeats every time on new import.
Both sites are project sites, both list has versioning enabled. Where else could be the problem???
I'm using these PowerShell commands:
Export-SPWeb -Identity <Site URL> -Path <string> -ItemUrl "<list path>" -Force
Import-SPWeb -Identity <Another Site URL> -Path "file.cmp" -Force -UpdateVersions Overwrite
EDIT:
So I ended up using this PowerShell script:
try {
# Export the list
Export-SPWeb -Identity <Site URL> -Path <string> -ItemUrl "<list path>" -Force
# Get the destination web and delete the list
$web = Get-SPWeb "<Site URL>"
$listToDelete = $web.Lists["List name"]
if ($listToDelete -ne $null) {
$web.Lists.Delete($listToDelete.ID)
Write-Host "List deleted successfully."
} else {
Write-Host "List not found on the destination web."
}
# Import the list
Import-SPWeb -Identity <Site URL> -Path "file.cmp" -Force -UpdateVersions Overwrite
Write-Host "List imported successfully."
}
catch {
Write-Host "An error occurred: $_.Exception.Message"
}
finally {
# Dispose of the SPWeb object
if ($web -ne $null) {
$web.Dispose()
}
}
Import-SPWebYou can useRemove-PnPList -Identity "<list name>" -Recycle -Force