Upload Files to SharePoint using PowerShell


SharePoint admins occasionally have write PowerShell scripts to regularly extract some type of summary data from the SharePoint farm and then write that out to a file, usually in CSV format since PowerShell handles those so well. This is great for admins because we can just log onto the box and open the file to read the data, but what about the rest of the SharePoint team that also needs that data?

The obvious and “SharePointy” solution is to upload the CSV files to a SharePoint document library so that others on the team can easily access the data whenever they want and then use Excel to slice it to their heart’s content. However, there is a problem: PowerShell has no way of uploading those files into SharePoint! Even if it did, SharePoint document libraries have so many configuration possibilities that it could get hairy quickly.

I wrote the script below to get around that. It can be called from other scripts and allows for:

  • Major and Minor Versioning
  • Check Out (if required)
  • Check In with comment
  • Approval with comment (if required)
  • Usage of the original file’s timestamps for SharePoint’s Created/Modified fields

    Check In and Approval updates the Modified date so that the file date will not be reflected in those cases

The script is still a little rough but seems to work for most cases.

Advertisements

Posted on May 2, 2013, in SharePoint and tagged , , , . Bookmark the permalink. 4 Comments.

  1. Am getting the below error , do you have any idea ?

    Unable to open site ‘http://sample.com/SSIS/Lists/Test/’ – Unable to find type [Microsoft.SharePoint.SPSite]
    : make sure that the assembly containing this type is loaded.

  2. You most likely need to load the SharePoint libraries into PowerShell as detailed here : http://sharepointpromag.com/blog/powershell-and-sharepoint-step-1-loading-dlls-and-snap-ins.

  3. Is the script available for download? I cannot find a download link.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s