{"id":5383,"date":"2019-09-02T07:25:42","date_gmt":"2019-09-02T07:25:42","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=5383"},"modified":"2019-09-02T07:25:42","modified_gmt":"2019-09-02T07:25:42","slug":"upload-and-download-a-file-using-pnp-powershell","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/","title":{"rendered":"Upload and Download a File using PnP PowerShell"},"content":{"rendered":"\n<p> In this blog, we will see how to upload a file to a document library and how to download the file to the local path.<\/p>\n\n\n\n<p>&nbsp;<strong>First, we need to connect to the site. To perform the connection, add the following lines.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ SiteUrl = Read-Host \"Provide site url\"\n$LocalPathForUpload = Read-Host \"Provide the path from where file to be uploaded\"\n$LocalPathForDownload = Read-Host \"Provide the path from where file to be uploaded\"\n$DocumentLibrary = Read-Host \"Provide the library name for upload or download file\"\n$Credentials = Get-Credential \/\/ It will open a pop up window and ask for credentials\nConnect-PnPOnline -Url $SiteUrl -Credentials $Credentials<\/code><\/pre>\n\n\n\n<p><strong>To Upload a file, add the following codes<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$File = Add-PnPFile -Path $LocalPathForUpload -Folder $DocumentLibrary\nWrite-Host \"Title : \" $File.Name\nWrite-Host \"URL : \" $File.ServerRelativeUrl<\/code><\/pre>\n\n\n\n<p><strong>To download the same file, add the following codes<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$filePath= $ DocumentLibrary + \"\/test.docx\"\nGet-PnPFile -Url $filePath -Path $ LocalPathForDownload -Filename \u201ctest.docx \" -AsFile\nWrite-Host \"File Downloaded Successfully\"<\/code><\/pre>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Output-<\/span><\/strong><\/p>\n\n\n\n<p>From the below images we can see our code run correctly and file uploaded and downloaded successfully. <\/p>\n\n\n\n<p><strong>Img1: PowerShell code runs successfully for upload and downloads a file.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/PowerShell-code-run-successfully--1024x549.jpg\" alt=\"\" class=\"wp-image-5384\"\/><\/figure>\n\n\n\n<p><strong>Img2: File uploaded to SharePoint document library.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/File-uploaded-to-SharePoint-document-library-1024x310.jpg\" alt=\"\" class=\"wp-image-5385\"\/><\/figure>\n\n\n\n<p><strong>Img3: File downloaded to given local path<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/File-downloaded-to-given-local-path-1024x190.jpg\" alt=\"\" class=\"wp-image-5386\"\/><\/figure>\n\n\n\n<p><strong>This solution is brought to you by our SharePoint professionals.<\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.softreetechnology.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Softree Technology<\/a><\/strong>&nbsp;employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.<\/p>\n\n\n\n<p>Be it SPFx or SharePoint add-in developments,&nbsp;<strong><a href=\"https:\/\/www.softreetechnology.com\/sharepoint-2019-developments\/\" target=\"_blank\" rel=\"noreferrer noopener\">SharePoint 2019 developments<\/a><\/strong>, web part developments, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016\/Office 365, Office 365,&nbsp;SharePoint hosted apps development&nbsp;or something else in SharePoint, we strive to deliver the best<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will see how to upload a file to a document library and how to download the file to the local path. &nbsp;First, we need to connect to the site. To perform the connection, add the following lines. To Upload a file, add the following codes To download the same file, add the following codes Output- From [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5389,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[298,43],"tags":[296,297,299,300,301],"class_list":["post-5383","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pnp-powershell","category-sharepoint","tag-download-a-file-from-sharepoint-library-to-local-path-using-pnp-powershell","tag-file-upload-and-download-in-sharepoint-using-pnp-powershell","tag-upload-a-file-to-sharepoint-library-using-pnp-powershell","tag-upload-and-download-file-from-sharepoint-using-pnp-powershell","tag-upload-and-download-file-using-pnp-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Upload and Download a File using PnP PowerShell - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Upload and Download a File using PnP PowerShell - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, we will see how to upload a file to a document library and how to download the file to the local path. &nbsp;First, we need to connect to the site. To perform the connection, add the following lines. To Upload a file, add the following codes To download the same file, add the following codes Output- From [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-02T07:25:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Upload and Download a File using PnP PowerShell - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Upload and Download a File using PnP PowerShell - Softree Technology","og_description":"In this blog, we will see how to upload a file to a document library and how to download the file to the local path. &nbsp;First, we need to connect to the site. To perform the connection, add the following lines. To Upload a file, add the following codes To download the same file, add the following codes Output- From [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/","og_site_name":"Softree Technology","article_published_time":"2019-09-02T07:25:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Upload and Download a File using PnP PowerShell","datePublished":"2019-09-02T07:25:42+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/"},"wordCount":198,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"","keywords":["download a file from sharepoint library to local path using pnp powershell","file upload and download in sharepoint using pnp powershell","Upload a file to SharePoint library using pnp powershell","upload and download file from sharepoint using pnp powershell","upload and download file using pnp powershell"],"articleSection":["PnP PowerShell","SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/","name":"Upload and Download a File using PnP PowerShell - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"","datePublished":"2019-09-02T07:25:42+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/upload-and-download-a-file-using-pnp-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Upload and Download a File using PnP PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=5383"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5383\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=5383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=5383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=5383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}