# Make sure the SharePoint namespace
is loaded
add-pssnapin Microsoft.SharePoint.PowerShell –erroraction silentlycontinue;
# Set some sample variables
$weburl = "http://contoso.local/sites/Classes/USHistory";
$libraryname = "Materials";
$presentationtitle = "Civil War
Weapons";
$files = ("E:\Civil War
Weapons\Weapons.pptx", "E:\Civil
War Weapons\Syllabus.pdf");
# Get the SPWeb object
$web = get-spweb $weburl;
# Get the content id of the
presentation document set
$ctId = $web.contenttypes["Presentation"].id.tostring();
# Get the SPList object
$list = $web.lists.trygetlist($libraryname);
if ($list –eq $null)
{
# List not found, do error processing
throw new-object ArgumentNullException($libraryname, "Library was
not found!")
}
$folder = $list.rootfolder;
# Create a hash table for the custom
property values
$hash = $null;
$hash = @{};
$hash.add("Presentation Date", get-date "5/12/2014 11:00 AM");
$hash.add("Presentater Name",
"Joseph Assif");
$hash.add("Presentater Email",
"jassif@university.edu");
$hash.add("Presentation Summary", "Lecture on the various weapons that were
used during the US Civil War");
# Create the new presentation
document set container
$newPresentation = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.rootfolder, $presentationtitle, $list.contenttypes.bestmatch($ctId), $hash);
$newPresentation.provision();
# If needed, you can capture the id
$newId = $newPresentation.item.id;
# Process the files for the document
set
foreach
($file in $files)
{
# Read the file
$f = get-childitem $file;
$filestream = ([System.IO.FileInfo] (get-item $f.fullname)).openread();
# Create the file in the document set
$target
= "{0}/{1}/{2}" –f $folder,
$presentationtitle, $f.name;
[Microsoft.SharePoint.SPFile]$spFile
= $folder.files.add($target, [System.IO.Stream]$filestream, $true);
$filestream.close();
# Set any file properties you may have defined
$spFile.item["Title"] = "Your document
title text");
$spFile.item.update();
# Other document processes needed (checkin, etc.)
} #
end foreach file
# Release SPWeb from memory
$web.dispose();
|