Donnerstag, 3. Februar 2011

Dokumente von Filesystem automatisch nach SharePoint importieren

Hallo zusammen,

anbei ein kleines PowerShell Skript, dass alle Dateien aus einem Ordner des Filesystems in eine SharePoint Liste importiert. Mir hat das Skript schon oft geholfen, ob als Hilfe für Datenmigration oder ob als geplanter Windows Tasks, der frisch eingescannte Dokumente regelmäßig importiert. Natürlich ist es möglich, automatisch Metadaten an die neu nach SharePoint hinzugefügten Dokumente anzufügen oder den Ersteller oder das Erstellungs-Datum vom Filesystem nach SharePoint zu importieren - aber Ihr werdet da schon die nötige Phantasie mitbringen :-)

  1. if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)   
  2. {   
  3.     Add-PSSnapin Microsoft.SharePoint.PowerShell   
  4. }   
  5.   
  6. $web = Get-SPWeb -Identity "http://sites/web/" ### Set your web URL   
  7. $folder = $web.GetFolder("http://site/web/list") ### Set your List URL here   
  8.   
  9.     foreach ($file in Get-ChildItem -Path "c:\folderwithdocuments") ### Set the location path of the folder with the documents here   
  10.     {   
  11.         $bytes  = [System.IO.File]::ReadAllBytes($file.Fullname)   
  12.         $SPDoc = $folder.Files.Add($file.Name,$bytes,$true)   
  13.         $SPDoc.Update()   
  14.         WRITE-HOST $file.FullName + " successfully added!" -ForegroundColor Green   
  15.     }   
  16. $web.Dispose()  

Ich hoffe es hilft!

Good luck,

Andreas

Keine Kommentare:

Kommentar veröffentlichen