here is my issue. I had an incident last week on my sharepoint infrastructure and a lot of files has been moved to different wrong libraries. I made an extraction from sql to find all this bad files and exported this selection to a csv. Now I'm trying to write a script in order to move this files (with their metadatas) to their correct libraries.
I've tried following this example : https://www.sharepointdiary.com/2016/03/copy-files-between-document-libraries-using-powershell-in-sharepoint.html
And did something like this :
##Script copie de fichiers d'une librairie à une autre
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-Transcript -Path c:\temp\transcript.txt
#Variables
$WebURL="http://MySPurl"
$ListingTESTQual = Import-Csv -Path C:\temp\TestQualifMoveSP.csv -Delimiter ';' -Encoding UTF8
$SourceFileTEST = $ListingTESTQual.URLactuelle
$TargetLibrary = "TempoCourrier_MED"
#Get Objects
$Web = Get-SPWeb $WebURL
$SourceFileTEST = $Web.GetFile($SourceFileTEST)
#Copie Meta-Data
#$ItemPREV = $FilePREV.Item
#$ItemFSS = $FileFSS.Item
foreach($fichiers in $ListingTESTQual)
{
if ($ListingTESTQual.NomLot -match "PRE")
{
$FilePREV = $TargetLibrary.Files.Add($SourceFileTEST.Name, $SourceFileTEST.OpenBinary(), $true)
$ItemPREV = $FilePREV.item
$ItemPREV["Created"] = $SourceFileTEST.TimeCreated.ToLocalTime()
$ItemPREV["Modified"] = $SourceFileTEST.TimeLastModified.ToLocalTime()
$ItemPREV["Author"] = $SourceFileTEST.Author
$ItemPREV["Editor"] = $SourceFileTEST.ModifiedBy
$ItemPREV["STATUT"] = $SourceFileTEST.STATUT
$ItemPREV["DateNumerisation"] = $SourceFileTEST.DateNumerisation
}
else {
if ($ListingTESTQual.NomLot -match "FSS")
{
$FileFSS = $TargetLibrary.Files.Add($SourceFileTEST.Name, $SourceFileTEST.OpenBinary(), $true)
$ItemFSS = $FileFSS.Item
$ItemFSS["Created"] = $SourceFileTEST.TimeCreated.ToLocalTime()
$ItemFSS["Modified"] = $SourceFileTEST.TimeLastModified.ToLocalTime()
$ItemFSS["Author"] = $SourceFileTEST.Author
$ItemFSS["Editor"] = $SourceFileTEST.ModifiedBy
$ItemFSS["STATUT"] = $SourceFileTEST.STATUT
$ItemFSS["DateNumerisation"] = $SourceFileTEST.DateNumerisation
}
}
}
#Update
$ItemPREV.UpdateOverwriteVersion()
$ItemFSS.UpdateOverwriteVersion()
My CSV looks like this :
NomLot;URLactuelle;NomFichier;URLdestination
PRE_Batch1.xml;http://ActualURL1;FileName1.pdf;http://DestinationURL1
FSS_Batch2.xml;http://ActualURL2;FileName2.pdf;http://DestinationURL2
And I got this mesage as soon as I run my script :
Exception lors de l'appel de «OpenBinary» avec «0» argument(s): «Le nom de
fichier ou de dossier contient des caractères non autorisés. Utilisez un autre
nom.»
Au caractère Ligne:6 : 9
+ $FilePREV = $TargetLibrary.Files.Add($SourceFileTEST.Name, $S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SPException
Impossible d’appeler une méthode dans une expression Null.
Au caractère Ligne:7 : 9
+ $ItemPREV["Created"] = $SourceFileTEST.TimeCreated.ToLocalTim ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Seems like there is a problem with a syntax, I've tried looking for the explanation but couldn't find
Any idea?
And it's not even entering my loop which is surely wrong!!