Mattias Wollnik from Microsoft has created a nifty PowerShell script that makes it much easier to move content from file shares into SharePoint 2007 and SharePoint 2010 beta sites. The FCI SharePoint Uploadscript is based on the File Classification Infrastructure(FCI) provided by Windows Server 2008 R2. The FCI allows administrators to setup policies that control the metadata associated with individual files. Using Mattias’ script, you can upload files and it will automatically set any matching metadata properties that are present in the target document library.
This is similar to the way that properties are promoted for Office 2007 documents, except that the script works for any file type. The File Classification Infrastructure provides a snap-in that lets you setup custom file management tasks. To use the script, you setup a new task that invokes PowerShell with the appropriate parameters.
For example, to upload files to a document library called “Company Files” in the Litware demo portal, you would specify an action type of “Custom” with the executable set to “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” and the arguments set to the following:
-noninteractive –file c:\scripts\FciSharePointUpload.ps1 –file “[Source File Path]” –url “http://litwareinc.com” –libPath “Company Files” –sourceAction url –user litwareinc\administrator –password pass@word1
The “[Source File Path]” string tells FCI to substitute the actual file path when the source files are processed. One cool feature is the ability to upload files directly to a SharePoint 2010 Records Center site, specifying the target content type on the command line. Using this feature, if any Content Organizer rules exist for the specified content type, they will be applied and processed automatically.
To do this, simply include the –useOfficialFileWebService parameter and then specify the content type using the –contentType parameter instead of -libPath, as in the following example:
-noninteractive –file c:\scripts\FciSharePointUpload.ps1 –useOfficialFileWebService –file “[Source File Path]” –url “http://litwareinc.com” –contentType “My Content Type” –sourceAction url –user litwareinc\administrator –password pass@word1
To learn more about the script with examples and a complete source code listing, visit http://gallery.technet.microsoft.com/ScriptCenter/en-us/f538c34c-4f74-4645-9649-fd25e49805d6.