Answered by:
How to Upload the ZIP folder to SharePoint (2010) Document Library using PowerShell

Question
-
Hi All,
As per below File Directory screenshot, I only want to upload 'Test1' ZIP folder to SharePoint (2010) Document Library using the PowerShell?
Any help would be really appreciated. Thank you.
Cheers, Badal Ratra MCTS
Sunday, July 31, 2016 1:04 PM
Answers
-
Hi Badal,
We can use the PowerShell below to upload the zip file to document library. The "DL" is my document library name, please change it to your document library name.
# Set the variables $WebURL = "http://sp2010:6262" $DocLibName = "DL" $FilePath = "C:\Temp\Test1.zip" # Get a variable that points to the folder $Web = Get-SPWeb $WebURL $List = $Web.GetFolder($DocLibName) $Files = $List.Files # Get just the name of the file from the whole path $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) # Load the file into a variable $File= Get-ChildItem $FilePath # Upload it to SharePoint $Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) $web.Dispose()
Best Regards,
Dennis
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.- Edited by Dennis Guo Monday, August 1, 2016 2:01 AM
- Proposed as answer by Patrick_Liang Friday, August 5, 2016 8:45 AM
- Marked as answer by Patrick_Liang Monday, August 8, 2016 10:01 AM
Monday, August 1, 2016 1:59 AM
All replies
-
Can you tell us a bit more? Will you be doing this from a SharePoint server or a remote PC. Is this for SharePoint on premise or SharePoint Online?
Here's a one line PowerShell solution that can be run on the SharePoint server:
(Get-SPWeb "http://server/sites/yoursite").GetFolder("Team Documents").Files.Add("Team Documents/myTestFile.txt", (Get-ChildItem "C:\test\myTestFile.txt").OpenRead(), $True)
There are several more examples here: http://techtrainingnotes.blogspot.com/2015/09/upload-file-to-sharepoint-using.html
Mike Smith TechTrainingNotes.blogspot.com
Books: SharePoint 2007 2010 Customization for the Site Owner, SharePoint 2010 Security for the Site OwnerSunday, July 31, 2016 3:37 PM -
Hi Mike,
It's SharePoint Server 2010 on premise and want to run the script from SharePoint Server.
Thank you.
Cheers, Badal Ratra MCTS
Sunday, July 31, 2016 10:42 PM -
Hi Badal,
We can use the PowerShell below to upload the zip file to document library. The "DL" is my document library name, please change it to your document library name.
# Set the variables $WebURL = "http://sp2010:6262" $DocLibName = "DL" $FilePath = "C:\Temp\Test1.zip" # Get a variable that points to the folder $Web = Get-SPWeb $WebURL $List = $Web.GetFolder($DocLibName) $Files = $List.Files # Get just the name of the file from the whole path $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) # Load the file into a variable $File= Get-ChildItem $FilePath # Upload it to SharePoint $Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) $web.Dispose()
Best Regards,
Dennis
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.- Edited by Dennis Guo Monday, August 1, 2016 2:01 AM
- Proposed as answer by Patrick_Liang Friday, August 5, 2016 8:45 AM
- Marked as answer by Patrick_Liang Monday, August 8, 2016 10:01 AM
Monday, August 1, 2016 1:59 AM -
Please refer to this earlier thread i.e. How to upload a zip package to a library with powershell:
https://social.technet.microsoft.com/Forums/en-US/d7d62af0-4c1a-4a9b-abcd-837715c9b6d6/how-to-upload-a-zip-package-to-a-library-with-powershell?forum=sharepointdevelopment
How to import (upload) an entire folder of files to SharePoint using PowerShell:
https://camerondwyer.wordpress.com/2013/05/27/how-to-import-upload-an-entire-folder-of-files-to-sharepoint-using-powershell/Here some another earlier threads might helps you to get in more detailed:
Upload document to folder in document library using powershell:
https://social.msdn.microsoft.com/Forums/en-US/3146c0c3-cd97-454b-8b4f-3cd60843827d/upload-document-to-folder-in-document-library-using-powershell?forum=sharepointadmin
Create a zip file from a folder on local file system and then upload it to a sharepoint document library programmatically :
https://social.msdn.microsoft.com/Forums/en-US/025d2182-ed34-4033-a65f-3bc7cec7b2b8/create-a-zip-file-from-a-folder-on-local-file-system-and-then-upload-it-to-a-sharepoint-document?forum=sharepointdevelopmentlegacyHope this helps!
A comprehensive solution to migrate to-and-from SharePoint and Office 365 along with File Servers, Exchange/Office 365 Public Folders, Google Drive and OneDrive Business to SharePoint Online/On-premise migration.
Monday, August 1, 2016 7:01 AM